Created
August 25, 2017 16:23
-
-
Save axayjha/54a054a8b0f282fa705fd8a231095bc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=[(2,3), (1,2), (3,1), (1,3), (3,2), (2,4), (4,1)] | |
##answer= [(1,2), (1,3), (1,4), (2,1), (3,2), (3,4), (4,2), (4,3)] | |
b=[(2,3), (1,2)] | |
c=[(1,2),(3,4), (5,6)] | |
def onehop(pairs): | |
res=[] | |
for i in range(len(pairs)): | |
for j in range(len(pairs)): | |
if pairs[i][1]==pairs[j][0] and pairs[i][0]!=pairs[j][1]: | |
res.append((pairs[i][0], pairs[j][1])) | |
return sorted(set(res)) | |
print(onehop(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment