Answers for "python tuple key dictionary"

0

python tuple key dictionary

'''
Dictionaries need hashable data as key.
Lists are not hashable so you can't use them as a key.
Tuples are hashables.
A way to do is to convert list to tuple before using them as a
 dictionary key
'''
Posted by: Guest on October-29-2021
-1

dictionary to tuple python

# Python code to convert dictionary into list of tuples
 
# Initialization of dictionary
dict = { 'Geeks': 10, 'for': 12, 'Geek': 31 }
 
# Converting into list of tuple
list = list(dict.items())
 
# Printing list of tuple
print(list)
Posted by: Guest on July-26-2021

Code answers related to "python tuple key dictionary"

Python Answers by Framework

Browse Popular Code Answers by Language