python - Elegant, pythonic solution for forcing all keys and values to lower case in nested dictionaries of Unicode strings? -
I'm curious about how Python Nijjas will do the following, gracefully and pictorially around:
I have a data structure that is unicode string decoded for units in Unicode string list from Unicode strings. Therefore:
& gt; & Gt; & Gt; Type (mindict) & lt; Type 'dict' & gt; & Gt; & Gt; & Gt; Type (mydict [u'myKey ']) & lt; Type 'dict' & gt; & Gt; & Gt; & Gt; Type (mydict [u'myKey '] [u'myKey2']) & lt; Type 'list' & gt; & Gt; & Gt; & Gt; Type (mydict [u'myKey '] [u'myKey2'] [0]) & lt; Type 'Unicode' & gt; I have to go through this and make every string in lowercase, that means every key and every string in each list.
How would you do this?
is really the simplest way, though I am not sure that you call it pythonic:
newDict = eval (repr (myDict). ()) Cleanly:
in v2 for v2 in v2) newDict = dict (1 k1.lower (), dict ((k2.lower (), [s.lower (in v2)) v1.iteritems ())) for 1, v1 myDict. Iteritems ())
Comments
Post a Comment