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.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to