Last active
August 29, 2015 14:06
-
-
Save hahastudio/e1d4bb5423be3052935b to your computer and use it in GitHub Desktop.
dict split in https://www.v2ex.com/t/133087
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d = { | |
"A0801_000000_201301": "1,321.8", | |
"A0801_000000_201302": "1,199.8", | |
"A0801_000000_201309": "1,433.4", | |
"A0802_000000_201305": "6,688.3", | |
"A0802_000000_201306": "8,085.2", | |
"A0802_000000_201307": "9,481.0", | |
"A0802_000000_201308": "10,878.4", | |
"A0802_000000_201309": "12,311.8", | |
"A0802_000000_201310": "13,739.9", | |
} | |
new_d = {} | |
for k in d: | |
key, mid, subkey = k.split('_') | |
new_d.setdefault(key, {})[subkey] = d[k] | |
print new_d | |
#result | |
""" | |
{ | |
'A0801': { | |
'201309': '1,433.4', | |
'201302': '1,199.8', | |
'201301': '1,321.8' | |
}, | |
'A0802': { | |
'201310': '13,739.9', | |
'201308': '10,878.4', | |
'201309': '12,311.8', | |
'201305': '6,688.3', | |
'201306': '8,085.2', | |
'201307': '9,481.0' | |
}, | |
} | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment