Skip to content

Instantly share code, notes, and snippets.

@Irene-123
Created July 13, 2020 03:31
Show Gist options
  • Save Irene-123/b99d8f0cc637b0824aa46fce93ab186e to your computer and use it in GitHub Desktop.
Save Irene-123/b99d8f0cc637b0824aa46fce93ab186e to your computer and use it in GitHub Desktop.
Symmetric pairs in python
```
def symmetric_pairs(d):
for key in d:
val = d[key]
if d[val] == key:
return(val,key)
return -1,-1
if __name__ == "__main__":
n=int(input("Enter the number of elements: \n"))
d = dict(input().split() for _ in range(n))
result=symmetric_pairs(d)
print(result)
```
```
Input:
5
1 3
2 3
3 1
4 5
5 4
```
```
Output:
('3','1')
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment