Python dictionaries

by: Trout, 9 years ago


hi,
in relation to python dictionaries is it possible to keep on adding to the dictionary to keep on expanding it.

I understand how to add values to the dictionary

score ={S: 22,S: 32,E: 43,R: 29}
score2 = {T: 100}
score.update(score2)
print (score)




how could I amend this code to keep on adding values and saving the added values in the dictionary.So if  i run the code again {T:100} will be in the dictionary and I can then add another value

thanks :)



You must be logged in to post. Please login or register an account.



you can say score[t] = newvalue. In your code, you could simply have
score ={S: 22,S: 32,E: 43,R: 29}
score[t] = 100
print(score)


If you convert values to a list, you can also append to the list, but this seems more like you're counting letters or something, so you just simply redefine the value.

-Harrison 9 years ago

You must be logged in to post. Please login or register an account.