python dict list search code example
Example 1: search in dict python
dictionary = { "key1" : 1, "name" : "Jordan", "age" : 21 }
for key in dictionary.keys():
print("the key is {} and the value is {}".format(key, dictionary[key]))
# or print("the key is",key,"and the value is",dictionary[key])
# OUTPOUT
# the key is key1 and the value is 1
# the key is name and the value is Jordan
# the key is age and the value is 21
Example 2: python list of dictionaries
new_player1 = { 'firstName': 'LaMarcus', 'lastName': 'Aldridge', 'jersey': '12', 'heightMeters': '2.11', 'nbaDebutYear': '2006', 'weightKilograms': '117.9'}
new_player2 = { 'firstName': 'LeBron', 'lastName': 'James', 'jersey': '2', 'heightMeters': '2.03', 'nbaDebutYear': '2003', 'weightKilograms': '113.4' }
new_player3 = { 'firstName': 'Kawhi', 'lastName': 'Leonard', 'jersey': '2', 'heightMeters': '2.01', 'nbaDebutYear': '2011', 'weightKilograms': '104.3' }
nba_players = []
nba_players.append(player)
nba_players.append(new_player1)
nba_players.append(new_player2)
nba_players.append(new_player3)