[Tutor] dictionary question

DS ds-python-tutor at sidorof.com
Fri Nov 11 22:59:29 CET 2005

You almost have it. Do this instead.

d = {'first':[]}

Append acts on the list, so assignment is unnecessary.


Eric Walker wrote:

>I have a dictionary say:
>d = {'first':[]}
>I am going through another list and depending on whats going on,
>I want to add to the empty list. I have tried the following to noavail.
>d['first'] = d['first'].append("string")
>I would think this would result in the dictionary key first's empty list  to 
>become ["string"].  can anyone help clear my head?
>Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list