Example 1:
Input: (1,2),(2,1),(3,4),(4,5),(5,4)
Output: (2,1) (5,4)
Explanation: Since (1,2) and (2,1) are symmetric pairs and (4,5) and (5,4) are symmetric pairs.
Example 2:
Input: (1,5),(2,3),(4,2),(5,1),(2,4)
Output: (2,4) (5,1)
Explanation: Since (1,5) and (2,4) are symmetric pairs and (5,1) and (4,2) are symmetric pairs.
Solution:
x=input().replace(")","")
x=x.replace("(","")
x=list(map(int, x.split(",")))
#print(x)
y = []
for i in range(0,len(x),2):
t=[x[i],x[i+1]]
y.append(t)
print(y)
#z = sorted(y, key=lambda x: x[0])
#print(z)
z=y
for i in range(len(z)):
for j in range(i+1,len(z)):
if z[i][0]==z[j][1] and z[i][1]==z[j][0]:
print("("+str(z[j][0])+","+str(z[j][1])+")", end=" ")