Question: Python code! Write a function lookupVal that takes a list of dictionaries L and a key k as input and checks each dictionary in L

Python code!

Write a function lookupVal that takes a list of dictionaries L and a key k as input and checks each dictionary in L starting from the end of the list. If k appears in a dictionary, lookupVal returns the value for key k. If k appears in more than one dictionary, it will return the one that it finds first (closer to the end of the list). For example:

L1 = [{"x":1,"y":True,"z":"found"},{"x":2},{"y":False}]

lookupVal(L1,"x") returns 2

lookupVal(L1,"y") returns False

lookupVal(L1,"z") returns "found

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!