Skip to content

Instantly share code, notes, and snippets.

@hahastudio
Last active August 29, 2015 14:06
Show Gist options
  • Save hahastudio/e1d4bb5423be3052935b to your computer and use it in GitHub Desktop.
Save hahastudio/e1d4bb5423be3052935b to your computer and use it in GitHub Desktop.
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