I'm trying to get values from a nested dict via user input. The problem is that the nested dictionaries have generic names (d1,d1, etc.). The user inputs, say, last name and the program returns the email.
I know this is basic, so I apologize in advance. This is what I have so far.
my_dict = {
'd1':{
'fname':'john',
'lname':'doe',
'age':'26',
'email':'[email protected]'
},
'd2':{
'fname':'mary',
'lname':'jane',
'age':'32',
'email':'[email protected]'
}
}
lname = input("enter last name: ")
for emp in my_dict.items():
print(emp)
Output:
enter last name: john
('d1', {'fname': 'john', 'lname': 'doe', 'age': '26', 'email': '[email protected]'})
('d2', {'fname': 'mary', 'lname': 'jane', 'age': '32', 'email': '[email protected]'})
my_dictuntil you find the person you're looking for with .items().