Ejemplo 1: cómo hacer una lista de claves que tengan los mismos valores
# 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))
Ejemplo 2: lista de pares clave-valor de Python
student = {"first_name": "Henry", "last_name": "Smith", "age": 20} # key: value
print(student["first_name"])
>>> Henry
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)