尝试这个:
from collections import defaultdict
loaded_items = {
'Apple0': 2,
'Apple1': 3,
'Apple2': 8,
'Mango':10,
'Banana': 15,
'Grape0': 11,
'Grape1': 20,
'Potato': 5
}
items = defaultdict(dict)
for k, v in loaded_items.items():
key_letter = ''.join(filter(str.isalpha, k))
items[key_letter][len(items[key_letter]) + 1] = v
print(items)
当年话下
相关分类