1res = defaultdict(list)
2for key, val in sorted(test_dict.items()):
3 res[val].append(key)
4
5
6#######################answer ##########################
7
8#The original dictionary : {'gfg': 1, 'is': 2, 'best': 1, 'for': 3, 'CS': 2}
9#Grouped dictionary is : {2: ['CS', 'is'], 1: ['best', 'gfg'], 3: ['for']}