-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
for i in range(number_vertices-1): | ||
for _ in range(number_vertices-1): | ||
for (u, v) in edges: | ||
relax(graph, u, v) | ||
for (u, v) in edges: | ||
if dist[v] > dist[u] + graph[u][v]: | ||
return False # there exists a negative cycle | ||
return True | ||
return all(dist[v] <= dist[u] + graph[u][v] for (u, v) in edges) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function bellman_ford
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
) - Use any() instead of for loop (
use-any
) - Invert any/all to simplify comparisons (
invert-any-all
)
This removes the following comments ( why? ):
# there exists a negative cycle
if bellman_ford(graph, s): | ||
return dist | ||
return "Graph contains a negative cycle" | ||
return dist if bellman_ford(graph, s) else "Graph contains a negative cycle" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_distances
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
table = [[0]*M for i in range(total+1)] | ||
table = [[0]*M for _ in range(total+1)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function coinchange
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
graph = dict() | ||
graph = {} | ||
with open(file) as f: | ||
for l in f: | ||
(u, v, w) = l.split() | ||
if int(u) not in graph: | ||
graph[int(u)] = dict() | ||
graph[int(u)] = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function read_graph
refactored with the following changes:
- Replace dict() with {} (
dict-literal
)
dist = dict() | ||
Q = list() | ||
|
||
for v in graph: | ||
dist[v] = inf | ||
Q = [] | ||
|
||
dist = {v: inf for v in graph} | ||
dist[s] = 0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function dijkstra
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace dict() with {} (
dict-literal
) - Replace list() with [] (
list-literal
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
for j in range(0, len(weights)): | ||
for j in range(len(weights)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function knapsack
refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range
)
cache = [[0 for j in range(n + 1)] for i in range(m + 1)] | ||
cache = [[0 for _ in range(n + 1)] for _ in range(m + 1)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function longest_common_subsequence
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
for j in range(0, i): | ||
if nums[i] > nums[j]: | ||
if cache[j] + 1 > cache[i]: | ||
cache[i] = cache[j] + 1 | ||
location[i] = j | ||
for j in range(i): | ||
if nums[i] > nums[j] and cache[j] + 1 > cache[i]: | ||
cache[i] = cache[j] + 1 | ||
location[i] = j |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function longest_increasing_subsequence
refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range
) - Merge nested if conditions (
merge-nested-ifs
)
return max([item for rows in copy_matrix for item in rows]) | ||
return max(item for rows in copy_matrix for item in rows) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function find_sub_matrix_size
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
raise Exception("Edge (%s, %s) already added in the graph" % (u, v)) | ||
raise Exception(f"Edge ({u}, {v}) already added in the graph") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function digraph.add_edge
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!