How can I create a dictionary where the key is a tuple

How can I create a dictionary where the key is a tuple?

dict={} dict.update({value:{}})

>Solution :

Just like you’d do for any other key

tup1 = ('a', 'b', 'c', 'd', 'e')
tup2 = (1, 2, 3, 4, 5)
tup3 = ('A', 'B', 'C', 'D', 'E')

dict = {}
dict[tup1] = 'lowercase'
dict[tup2] = 'numbers'
dict[tup3] = 'uppercase'
print(dict)

{('a', 'b', 'c', 'd', 'e'): 'lowercase', (1, 2, 3, 4, 5): 'numbers', ('A', 'B', 'C', 'D', 'E'): 'uppercase'}

Leave a Reply