0

ONE HOP FLIGHT PROBLEM

Write a Python function onehop(l) that takes as input a list of pairs representing direct flights, as described above, and returns a list of all pairs (i,j), where i != j, such that i and j are connected by one hop. Note that it may already be the case that there is a direct flight from i to j. So long as there is an intermediate k with a flight from i to k and from k to j, the list returned by the function should include (i,j). The input list may be in any order. The pairs in the output list should be in lexicographic (dictionary) order. Each pair should be listed exactly once. For instance >>> onehop([(2,3),(1,2)]) [(1, 3)] >>> onehop([(2,3),(1,2),(3,1),(1,3),(3,2),(2,4),(4,1)]) [(1, 2), (1, 3), (1, 4), (2, 1), (3, 2), (3, 4), (4, 2), (4, 3)] >>> onehop([(1,2),(3,4),(5,6)]) []

24th Aug 2017, 6:53 AM
ASIF RAJA M
1 Answer
0
is this what your looking for? https://code.sololearn.com/cF3WxtsCaHiM/#py
18th Sep 2017, 5:33 PM
NulledNVoided
NulledNVoided - avatar