Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
908 B
0
Indexable
Never
def spaceTravelers (a, b):
    origin = a[0]
    finalDestination = a[1]
    routes = b
    finalRoutes = []
    intermediateRoutes = []

    #Encontrar rutas intermedias y finales
    for route in routes:
        routeDestination = route.split(' ')[1]
        foundRouteOrigin = 0
        for r in routes:
            if (r.split(' ')[0] == routeDestination):
                foundRouteOrigin += 1
                intermediateRoutes.append(r)
        if (foundRouteOrigin == 0):
            finalRoutes.append(route)

    # Eliminar rutas intermedias de las finales
    for route in intermediateRoutes:
        #Chequear para mas de un item
        finalRoutes.remove(route)

    print('Rutas finales', finalRoutes)
    print('Rutas intermedias', intermediateRoutes)






spaceTravelers(['Mercury', 'Saturn'], ["Sun Earth", "Mercury Venus", "Mars Mercury", "Mercury Saturn"])