how to make list of keys which has same values

Solutions on MaxInterview for how to make list of keys which has same values by the best coders in the world

showing results for - "how to make list of keys which has same values"
Alessandro
27 Apr 2017
1# Python code to demonstrate 
2# finding duplicate values from dictionary 
3
4# initialising dictionary 
5ini_dict = {'a':1, 'b':2, 'c':3, 'd':2} 
6
7# printing initial_dictionary 
8print("initial_dictionary", str(ini_dict)) 
9
10# finding duplicate values 
11# from dictionary using flip 
12flipped = {} 
13
14for key, value in ini_dict.items(): 
15	if value not in flipped: 
16		flipped[value] = [key] 
17	else: 
18		flipped[value].append(key) 
19
20# printing result 
21print("final_dictionary", str(flipped)) 
22