I have a dictionary with IDs and counts:
items_count = {
'1111:271': 111,
'1111:190': 3,
'1231:106': 13,
'1211:104': 111,
'1111:201': 9
}
Key is "category":"id". I want to separate category and put it in another dictionary like:
items_count2 = {
'1111': {'271': 111, '190': 3, '201': 0},
'1231': {'106': 13},
'1211': {'104': 111}
}
but when I do this
items_count2 = {k.split(':')[0]: {k.split(':')[1]: v} for k, v in items_count}
I get error "ValueError: too many values to unpack (expected 2)"
please help to understand, what am I doing wrong?