We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 7bd83fd + 13df43e commit 81fcb2fCopy full SHA for 81fcb2f
graphs/traveling_salesman_problem.py
@@ -110,10 +110,13 @@ def tsp_greedy(graph: list[list[int]]) -> int:
110
for _ in range(n - 1):
111
# Find the nearest city to the current location that has not been visited.
112
next_city = min(
113
- ((city, cost) for city, cost in enumerate(graph[current])
114
- if not visited[city] and city != current),
115
- key=lambda cost: cost[1],
116
- default=(None, float('inf'))
+ (
+ (city, cost)
+ for city, cost in enumerate(graph[current])
+ if not visited[city] and city != current
117
+ ),
118
+ key=lambda cost: cost[1],
119
+ default=(None, float("inf")),
120
)[0]
121
122
# If no such city exists, break the loop.
0 commit comments