Answers for "how to insert data in dictionary in python"

2

add values to dictionary key python

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

how to add a key and a value to a dictionary in python

diction = {'key':'value'}#Adding a dictionary called diction.
print(diction)
diction['newkey']='newvalue'#Adding the newkey key to diction with its value.
print(diction)
#output: {'key':'value','newkey':'newvalue'}
Posted by: Guest on October-07-2021

Code answers related to "how to insert data in dictionary in python"

Python Answers by Framework

Browse Popular Code Answers by Language