[Tutor] Bigrams and nested dictionaries

John Fouhy john at fouhy.net
Wed Mar 29 04:34:30 CEST 2006


On 29/03/06, Michael Broe <mbroe at columbus.rr.com> wrote:
> Well I ran into an interesting glitch already. For a dictionary D, I
> can pull out a nested value using this syntax:
>
>  >>> D['b']['a']
> 23
>
> and I can assign to this dictionary using
>
>  >>> D['d'] = {'a':7, 'b':0'}
>
> but I can't assign like this:
>
>  >>> D['d']['c'] = 1
> TypeError: object does not support item assignment.

I can't reproduce this...

>>> D = {}
>>> D['d'] = {'a':7, 'b':0}
>>> D['d']['c'] = 1
>>> D
{'d': {'a': 7, 'c': 1, 'b': 0}}

Are you sure you haven't mistakenly assigned something other than a
dict to D or D['d'] ?

--
John.


More information about the Tutor mailing list