[Tutor] dictionary question

Eric Walker ewalker at micron.com
Fri Nov 11 23:02:34 CET 2005


ahh man,
I should have known. sheesh python is so kewl. I keep forgetting most times, 
it will do stuff directly and you don't have to assign.. 

Thanks

Python Newbie....



On Friday 11 November 2005 02:59 pm, DS wrote:
> 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
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Eric Walker
EDA/CAD Engineer
Work: 208-368-2573


More information about the Tutor mailing list