As far as I can tell, your "sorting" of the result comes from the order of the original items in the categories dictionary.
Start by iterating over the keys and values of the categories dictionary:
result = {}
for cat, entries in categories.items(): # cat='CAT1', ent=['A', 'B', 'C']
The easy thing to do would be to use a defaultdict. But you can populate your resulting dictionary now with an empty list.
result[cat] = []
Now, iterate over the list of entries:
for entry in entries: # 'A', 'B', 'C'
Each entry
in the entries list is a key into the items
dictionary you provided, so look it up:
ent_items = items[entry] # ent_items = [1.0]
The result of that lookup (ent_items
) is a list of float numbers. Concatenate it to the correct list in the result dictionary:
result[cat] += ent_items # result['CAT1'] = [1.0]
Notice that I haven't sorted anything, because your example doesn't appear to sort anything. The ordering of the dictionary keys (categories) doesn't matter, and everything else is determined by the sequence of items in the lists.