I'm trying to write a function that takes a value for a given key (User_ID) and return the full dictionary for that value. I understand that this can probably be achieved without writing a function but as a beginner I'm trying to build my knowledge with functions.
My data is a list of dictionaries and looks like this:
[
{
"User_ID":"Z000",
"DOB":"01.01.1960",
"State":"Oregon",
"Bought":["P1","P2"]
},
{
"User_ID":"A999",
"DOB":"01.01.1980",
"State":"Texas",
"Bought":["P5","P9"]
}
]
I wrote the following function but I realized that this is would only work for a dictionary but I have a list of dictionaries. How can I make it to take the User_ID value and return the full dictionary including the User_ID, DOB, State and Bought.
def find_user(val):
for key, value in dict_1.items():
if val == key:
return value
return "user not found"