Skip to content

Commit 13df43e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ed8b6e3 commit 13df43e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

graphs/traveling_salesman_problem.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,13 @@ def tsp_greedy(graph: list[list[int]]) -> int:
110110
for _ in range(n - 1):
111111
# Find the nearest city to the current location that has not been visited.
112112
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'))
113+
(
114+
(city, cost)
115+
for city, cost in enumerate(graph[current])
116+
if not visited[city] and city != current
117+
),
118+
key=lambda cost: cost[1],
119+
default=(None, float("inf")),
117120
)[0]
118121

119122
# If no such city exists, break the loop.

0 commit comments

Comments
 (0)