Help about dictionary append

Anatoli Hristov tolidtm at gmail.com
Sun Feb 5 21:12:48 CET 2012


Thanks Chris,

It works fine, I see it will take time till I understand all the syntax :(

A.H

On Sun, Feb 5, 2012 at 4:20 PM, Chris Angelico <rosuav at gmail.com> wrote:

> On Mon, Feb 6, 2012 at 2:13 AM, Anatoli Hristov <tolidtm at gmail.com> wrote:
> > Hi there,
> >
> > I`m again confused and its the dictionary. As dictionary does not support
> > append I create a variable list with dictionary key values and want to
> add
> > new values to it and then copy it again to the dictionary as I dont know
> > other methods.
>
> A dictionary maps a key to exactly one value. If you want multiples,
> you do pretty much what you've done here...
>
> > mydict =
> > {'Name':('Name1','Name2','Name3'),'Tel':('023333','037777','049999')}
> >...
> > and I get and error that TUPLE object has no attribute Append !!!
> >
> > But how to add new Values to a dictionary then ?
>
> ... but instead of using parentheses and creating a Tuple, use square
> brackets and create a List:
>
> mydict =
> {'Name':['Name1','Name2','Name3'],'Tel':['023333','037777','049999']}
>
> Then you can append to it, and it will work just fine!
>
> Chris Angelico
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120205/d72ba638/attachment.html>


More information about the Python-list mailing list