Question

1.Define a function value_to_key(d,value) that takes in a dictionary and a value as a parameter. The...

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

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
define a function,character, with parameter values and word that takes in a dictionary of letter values...
define a function,character, with parameter values and word that takes in a dictionary of letter values and a string. Based on the values in the dictionary, return the "score" that corresponds with the word parameter. NOTE: Assume all words and letter values will be lowercase. examples: values = {'a': 5, 'b': 5, 'c': 5, 'd': 5, 'e': 5, 'f': 5, 'g': 5, 'h': 5, 'i': 5, 'j': 5, 'k': 5, 'l': 5, 'm': 5, 'n': 5, 'o': 5} character(value,"ade") will...
Write a python function that will taken in a df (dataframe) and return a dictionary with...
Write a python function that will taken in a df (dataframe) and return a dictionary with the corresponding data types. You may need to instantiate an empty dictionary in your function. The keys will be the column headers of the df and the values will be the data types.
Python Write the contents of the function below. It should build a dictionary with keys and...
Python Write the contents of the function below. It should build a dictionary with keys and values. For each such entry, it must enter two rows from the keyboard. The first line should constitute the key to be stored in a form with only capital letters. The user enters the value on the next row. This should be stored as an integer. If you enter a blank line as the key, the lock should end and the dictionary is returned....
In C++ 1) Write the function definition that has 1 pass by value integer parameter. The...
In C++ 1) Write the function definition that has 1 pass by value integer parameter. The function contains logic to return true if the parameter is even and false if it is not. 2 ) Write a main function that prompts the user for a value, calls the function that you created in step one with the value entered by the user, display "even" if the function return true and otherwise displays "odd"
1.Write a function which takes in a dictionary are returns the sum of the keys plus...
1.Write a function which takes in a dictionary are returns the sum of the keys plus the sum of the values, but only if all the keys and all the values are integers. Otherwise it returns False. >>>f({'a':1,'b':4,'c':7,'d':11}) False >>>f({1:2,3:4,5:6,7:8}) 36 2.Write a function to quickly compute the recaman sequence. 3. The Hofstadter Conway sequence is defined by a(1)=a(2)=1 and (for n>2 by) a(n)=a(a(n-1))+a(n-a(n-1)). Write a function to quickly compute this sequence. >>> [hc(i) for i in range(1,20)] [1, 1,...
Implement function build_dictionary(words) that returns a dictionary. The words parameter is a list of strings. Each...
Implement function build_dictionary(words) that returns a dictionary. The words parameter is a list of strings. Each word in the words parameter will be counted and you will build your dictionary around the frequency count. Each key of your dictionary will be the word in your list of strings and the corresponding value is an integer indicating the word’s frequency. Assume input is always valid. ‘Blue’ and ‘blue’ should be counted as the same word. [You may use lower() ONLY and...
Write a Python function first_chars that takes one parameter, which is a nested list of strings....
Write a Python function first_chars that takes one parameter, which is a nested list of strings. It returns a string containing the first character of all of the non-empty strings (at whatever depth they occur in the nested list) concatenated together. Here are a couple of examples of how the function should behave when you're done: >>> first_chars(['Boo', 'is', 'happy', 'today']) 'Biht' >>>first_chars(['boo', 'was', ['sleeping', 'deeply'], 'that', 'night', ['as', ['usual']]]) 'bwsdtnau'
10. Which of the following statements about python dictionary is correct? A. You can have different...
10. Which of the following statements about python dictionary is correct? A. You can have different types of data as keys in a dictionary. B. You can have variables as keys in a dictionary. C. The values (key-value pairs) in a dictionary must be the types of int or float. D. You cannot have a list as key in a dictionary.
Python coding: HW `declaration.py` * define function `calc_histogram(lines)` * returns histogram dictionary and total non-whitespace characters...
Python coding: HW `declaration.py` * define function `calc_histogram(lines)` * returns histogram dictionary and total non-whitespace characters * takes list of strings as argument * ignore comment lines denoted by `#` * if invoking script directly, load `data/declaration.txt` and calculate histogram * print histogram by sorted characters * count letter instances not characters, so `A` and `a` count as same (This is the local test I was given): if __name__ == '__main__': import os.path file_path = os.path.join("data", 'declaration.txt') print(file_path) letter =...
Python 3 Implement the function invert_and_merge, which takes any number of input dictionaries via a star...
Python 3 Implement the function invert_and_merge, which takes any number of input dictionaries via a star parameter, and inverts and merges them into a single result dictionary. When inverting a dictionary, the keys and values are flipped, so that each value maps to a set containing the corresponding key(s) in the original dictionary. When merging the inverted dictionaries, sets corresponding to the same key are combined. Examples: invert_and_merge({'a': 1, 'b': 2, 'c': 1, 'd': 1, 'e': 2}) should return {1:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT