[Tutor] Question on dictionary

Sunil Tech sunil.techspk at gmail.com
Fri Sep 12 18:51:13 CEST 2014


Thank you Danny and Joel :)

On Fri, Sep 12, 2014 at 9:51 PM, Joel Goldstick <joel.goldstick at gmail.com>
wrote:

> On Fri, Sep 12, 2014 at 12:04 PM, Danny Yoo <dyoo at hashcollision.org>
> wrote:
> >
> >> i wrote a code like this
> >>
> >> for i in res:
> >>     dict = {}
> >>     dict['id_desc'] = str(i['id'])+','+str(i['description'])
>
> A minor revision for the right side of above:
>    ",".join(str(i['id'], str(i['description']))
>
> >>     i.update(dict)
> >>
> >> is there any other simple methods to achieve this?
> >>
> >
> > Can you avoid the intermediate "dict" and just assign to i['id_desc']
> > directly?
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> >
>
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140912/fc25b87d/attachment.html>


More information about the Tutor mailing list