[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':[]}
d['first'].append("string")

Append acts on the list, so assignment is unnecessary.

ds

Eric Walker wrote:

>All,
>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?
>
>Thanks...
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>  
>



More information about the Tutor mailing list