Python Program to Convert Tuple to Dictionary

tup = ((11, "eleven"), (21, "mike"), (19, "dustin"), (46, "caleb"))
print(tup)
dct = dict((y, x) for x, y in tup)
print(dct)

OUTPUT:

((11, 'eleven'), (21, 'mike'), (19, 'dustin'), (46, 'caleb'))
{'eleven': 11, 'mike': 21, 'dustin': 19, 'caleb': 46}

Sharing Is Caring

Leave a Comment