Created
July 13, 2020 03:31
-
-
Save Irene-123/b99d8f0cc637b0824aa46fce93ab186e to your computer and use it in GitHub Desktop.
Symmetric pairs in python
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
``` | |
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