assosciate 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']}