Answers for "add values to dictionary key python"

37

add new keys to a dictionary python

d = {'key':'value'}
print(d)
# {'key': 'value'}
d['mynewkey'] = 'mynewvalue'
print(d)
# {'mynewkey': 'mynewvalue', 'key': 'value'}
Posted by: Guest on November-27-2019
2

add values to dictionary key python

key = "somekey"
a.setdefault(key, [])
a[key].append(2)
Posted by: Guest on December-30-2020

Code answers related to "add values to dictionary key python"

Python Answers by Framework

Browse Popular Code Answers by Language