1.Define a function value_to_key(d,value) that takes in a dictionary and a value as a parameter. The function will return a list of all the keys that correspond with that value. If the value does not appear in the dictionary, it will return an empty list.
ex.value_to_key({‘a’: 1, ‘b’: 4, ‘c’: 7}, 4) returns [‘b’]
2.Define a function input_tracker(number)that prompts the user to input values into the console a number of times.The function will return a dictionary where the keys are the different answers the user inputted and the values are the number of times the user inputted that particular answer. User inputs may remain String data types.
Ex. input_tracker(4) with inputs ‘A’, ‘C’, ‘B’, ‘A’ returns {‘A’: 2, ‘B’: 1, ‘C’: 1}
This is in python
def value_to_key(d,value):
data=[]
for i in d:
if d[i]==value:
data.append(i)
return data
def input_tracker(n):
d={}
for i in range(n):
ip=input()
if ip in d:
d[ip]+=1
else:
d[ip]=1
return d
Get Answers For Free
Most questions answered within 1 hours.