import networkx as nx def parades(digraf, origen, desti): if origen in digraf and desti in digraf and nx.has_path(digraf, origen, desti): r = ( nx.shortest_path_length(digraf, origen, desti)-1, nx.shortest_path(digraf, origen, desti)[1:][:-1] ) else: r = (-1, []) return r