def find_itinerary(start_city, start_time, end_city, deadline):
discovered = set()
depth = 0
import copy
def dfs(curr_city,curr_time,flight_tracker):
if curr_city == end_city:
return flight_tracker
for flight in flightDB:
if flight.end_city not in discovered and flight.match(curr_city,curr_time):
ft = copy.deepcopy(flight_tracker)
ft.append(flight)
dfs(flight.end_city,flight.end_time,ft)
return dfs(start_city,start_time,[])
The function above always returns None. I know why it returns None (the for loop dfs is not returned) but I dont know how to fix it. Also,I cannot put a return statement within the for loop as it will break the for loop. Is it possible to do recursive DFS that returns a value like a list?