# initialize list
test_list = [(4, 3), (2, 3), (3, 10), (5, 10), (5, 6)]
# printing original list
print("The original list : " + str(test_list))
# create a dictionary with the unique second elements of the tuples as the keys
temp = dict.fromkeys(set(x[1] for x in test_list), 0)
# iterate through the list of tuples and update the dictionary with the maximum key value pair
for x in test_list:
if x[0] > temp[x[1]]:
temp[x[1]] = x[0]
# create the final result
res = [(val, key) for key, val in temp.items()]
# printing result
print("The records retaining maximum keys of similar values : " + str(res))
# Output:
# The original list : [(4, 3), (2, 3), (3, 10), (5, 10), (5, 6)]
# The records retaining maximum keys of similar values : [(4, 3), (5, 10), (5, 6)]
#This code is contributed by Edula Vinay Kumar Reddy