How I can convert a Python Tuple into Dictionary?

Mahabubur Rahman
0


Tuple elements are enclosed inside parentheses, while dictionary elements appear as a key-value pair and are enclosed in curly braces.
i.e- 
(
(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

0Comments
Post a Comment (0)