In python
def reverse_lookup(input_dict, test_value):
# Complete this function to find all the keys in a dictionary that
map to the input value.
# input1: input_dict (dict)
# input2: test_value
# output: list of keys
# YOUR CODE HERE
It has to pass these tests
input_dict = {
'January': 31,
'February': 28,
'March': 31,
'April': 30,
'May': 31,
'June': 30,
'July': 31,
'August': 31,
'September': 30,
'October': 31,
'November': 30,
'December': 31,
}
assert reverse_lookup(input_dict, 31) == ['January', 'March', 'May', 'July', 'August', 'October', 'December']
def reverse_lookup(input_dict, test_value): # Complete this function to find all the keys in a dictionary that map to the input value. # input1: input_dict (dict) # input2: test_value # output: list of keys # YOUR CODE HERE result = [] for x in input_dict: if input_dict[x]==test_value: result.append(x) return result input_dict = { 'January': 31, 'February': 28, 'March': 31, 'April': 30, 'May': 31, 'June': 30, 'July': 31, 'August': 31, 'September': 30, 'October': 31, 'November': 30, 'December': 31, } assert reverse_lookup(input_dict, 31) == ['January', 'March', 'May', 'July', 'August', 'October', 'December']
Get Answers For Free
Most questions answered within 1 hours.