Answers for "associate keys as list to values in python"

0

associate keys as list to values in python

res = defaultdict(list)
for key, val in sorted(test_dict.items()):
    res[val].append(key)
    
    
#######################answer ##########################

#The original dictionary : {'gfg': 1, 'is': 2, 'best': 1, 'for': 3, 'CS': 2}
#Grouped dictionary is : {2: ['CS', 'is'], 1: ['best', 'gfg'], 3: ['for']}
Posted by: Guest on July-23-2021

Code answers related to "associate keys as list to values in python"

Python Answers by Framework

Browse Popular Code Answers by Language