[Tutor] Manipulating Dictionary values
Sunil Tech
sunil.techspk at gmail.com
Mon Dec 26 03:03:37 EST 2016
Hi Team,
Dictionary is like
a = {'a': 'New', 'b': 'Two', 'l': [{'k': 'test', 'm': 'again'}, {'k':
'test', 'm': 'again'}]}
I am trying to modify a value in the dictionary value at a['l'] & at 'm'
expecting it to be
a = {'a': 'New', 'b': 'Two', 'l': [{'k': 'test', 'm': 'replaced'}, {'k':
'test', 'm': 'replaced'}]}
for which I tried to do using list comprehension
>>> a['l'] = [i['m'].replace('again', 'replaced') for i in a['l']]
>>> a
{'a': 'New', 'b': 'Two', 'l': ['replaced', 'replaced']}
Any help will be appreciated.
More information about the Tutor
mailing list