How I can convert a Python Tuple into Dictionary?

Published 2 days ago5 min read4 comments

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')}