Re: [Tutor] Question on dictionary

2014-09-12 Thread Steven D'Aprano
On Fri, Sep 12, 2014 at 08:26:29PM +0530, Sunil Tech wrote: > Hi All, > > i have a dictionary like > > res = [{'description': 'Testo', 'id': '676', 'parentOf': True}, >{'description': 'Pesto', 'id': '620', 'parentOf': False}] That is not a dictionary. It is a list containing two dictiona

Re: [Tutor] Question on dictionary

2014-09-12 Thread Sunil Tech
Thank you Danny and Joel :) On Fri, Sep 12, 2014 at 9:51 PM, Joel Goldstick wrote: > On Fri, Sep 12, 2014 at 12:04 PM, Danny Yoo > wrote: > > > >> i wrote a code like this > >> > >> for i in res: > >> dict = {} > >> dict['id_desc'] = str(i['id'])+','+str(i['description']) > > A minor re

Re: [Tutor] Question on dictionary

2014-09-12 Thread Joel Goldstick
On Fri, Sep 12, 2014 at 12:04 PM, Danny Yoo 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

Re: [Tutor] Question on dictionary

2014-09-12 Thread Danny Yoo
> i wrote a code like this > > for i in res: > dict = {} > dict['id_desc'] = 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] Question on dictionary

2014-09-12 Thread Sunil Tech
Hi All, i have a dictionary like res = [{'description': 'Testo', 'id': '676', 'parentOf': True}, {'description': 'Pesto', 'id': '620', 'parentOf': False}] i looking for the result like this res = [{'description': 'Testo', 'id': '676', 'id_desc':'676_Testo', 'parentOf': True}, {'desc