How I can convert a Python Tuple into Dictionary?

Mahabubur Rahman

Tuple elements are enclosed inside parentheses, while dictionary elements appear as a key-value pair and are enclosed in curly braces.
(1, 'Pending'),
(2, 'Done'),
(3, 'Cancel')

In this article, we'll show you how to convert a Python tuple to a dictionary. We can use dict(tuple)
to convert tuple to dictionary.

Example - 
# input tuple
Tuple = ((1, 'Pending'),(2, 'Done'),(3, 'Cancel'))

print("The Tuple:",Tuple )

Dictionary = dict(Tuple)
print("The Dictionary:",Dictionary )  

Output -
 The input Tuple: (1, 'Pending'),(2, 'Done'),(3, 'Cancel')
 The result dictionary: {1:'Pending',2:'Done',3:'Cancel')}  

Post a Comment

Post a Comment (0)