Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

list of tuples from a dictionary in python

dic_1 = {'boys': 10, 'girls': 3, 'dogs': 5, 'cats': 6}
tup = dic_1.items()
print(type(tup))            # Output: <class 'dict_items'>
print(tup)                  # Output: dict_items([('boys', 10), ('girls', 3), ('dogs', 5), ('cats', 6)])
# You can convert it to a dictionary again if you want
dic_2 = dict(tup)
print(dic_2)                # Output: {'boys': 10, 'girls': 3, 'dogs': 5, 'cats': 6}
 
PREVIOUS NEXT
Tagged: #list #tuples #dictionary #python
ADD COMMENT
Topic
Name
8+4 =