[Tutor] Question on dictionary

Sunil Tech sunil.techspk at gmail.com
Fri Sep 12 16:56:29 CEST 2014


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},
{'description': 'Pesto',
  'id': '620',
'id_desc':'620_Pesto',
  'parentOf': False}]

to get this result

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?

Thanks,
Sunil. G
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140912/b6177082/attachment.html>


More information about the Tutor mailing list