+ 2

How can i assign two values to one key in dictionary python-datatype

suppose we have x = {"name":"mido","hobby":"football"} how can i add basketball as a 2nd value to the key "mido" in python 2.7

27th Mar 2018, 1:05 AM
Muhmd Ezz
Muhmd Ezz - avatar
2 ответов
+ 1
This works the same way as Jan's example except you can target the specific key. You still have to redefine all of the values in the key, but you can add to it this way. x = {'key0':'val0','key1':['val0','val1']} for i in x: print(x[i]) x['key1'] = ['val0','val1','val2'] print() for i in x: print(x[i])
27th Mar 2018, 6:07 AM
synorax
synorax - avatar
0
i want do that by code not manually
27th Mar 2018, 4:05 AM
Muhmd Ezz
Muhmd Ezz - avatar