Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Use FP, Luke! solution in Clear category for The Cheapest Flight by obone
from typing import List
def cheapest_flight(costs: List, a: str, b: str) -> int:
nextpath = lambda path, c: c[not c.index(path[-1])]
mk_route = lambda path: [c[2] + v
for c in costs if path[-1] in c and nextpath(path, c) not in path
for v in ([0] if b in c else mk_route(path + nextpath(path, c)))]
return min(mk_route(a), default = 0)
Aug. 24, 2019
Comments: