Skip to content

Instantly share code, notes, and snippets.

@axayjha
Created August 25, 2017 16:23
Show Gist options
  • Save axayjha/54a054a8b0f282fa705fd8a231095bc6 to your computer and use it in GitHub Desktop.
Save axayjha/54a054a8b0f282fa705fd8a231095bc6 to your computer and use it in GitHub Desktop.
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