[Tutor] append value to dictionary key

Chris Stinemetz chrisstinemetz at gmail.com
Fri Mar 6 15:28:24 CET 2015


I would like to append a value to a dictionary key where there is already a
value. Something like the below:

d = {'name': {'2': 0.0, '7': 10.0, '8': 0.0, '9': 0.0}}
append 10 to d['name']['2']
d = {'name': {'2': 0.0,10, '7': 10.0, '8': 0.0, '9': 0.0}}

When I try to this I get the following error:
>>> d['name']['2'].append(10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'float' object has no attribute 'append'

I am obviously doing this wrong. How would I accomplish this?

Thank you in advance.


More information about the Tutor mailing list