[Tutor] Question on dictionary
Joel Goldstick
joel.goldstick at gmail.com
Fri Sep 12 18:21:07 CEST 2014
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
More information about the Tutor
mailing list