Answers for "how to make list of keys which has same values"

0

how to make list of keys which has same values

# Python code to demonstrate 
# finding duplicate values from dictionary 

# initialising dictionary 
ini_dict = {'a':1, 'b':2, 'c':3, 'd':2} 

# printing initial_dictionary 
print("initial_dictionary", str(ini_dict)) 

# finding duplicate values 
# from dictionary using flip 
flipped = {} 

for key, value in ini_dict.items(): 
	if value not in flipped: 
		flipped[value] = [key] 
	else: 
		flipped[value].append(key) 

# printing result 
print("final_dictionary", str(flipped))
Posted by: Guest on February-17-2021

Code answers related to "how to make list of keys which has same values"

Python Answers by Framework

Browse Popular Code Answers by Language