def add_flight(routes, index): route = routes[index] if len(route.flights()[-1].connections) == 0: return routes if len(route.flights()[-1].connections) > 1: for connection in route.flights()[-1].connections[1:]: new = Route(route.flights()[0]) for flight in route.flights()[1:]: new.add_route(flight) new.add_route(connection) routes.append(new) route.add_route(route.flights()[-1].connections[0]) add_flight(routes, index) return routes