On 15/10/2011 19:00, Gnarlodious wrote:
What is the best way (Python 3) to loop through dict keys, examine the
string, change them if needed, and save the changes to the same dict?
So for input like this:
{'Mobile': 'string', 'context': '<malicious code>', 'order': '7',
'time': 'True'}
I want to booleanize 'True', turn '7' into an integer, escape
'<malicious code>', and ignore 'string'.
Any elegant Python way to do this?
How about:
for key, value in my_dict.items():
if value == "True":
my_dict[key] = True
--
http://mail.python.org/mailman/listinfo/python-list