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.
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"
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 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:...
On python a) Create a dictionary with 5 to 10 key-values so that state is the...
On python a) Create a dictionary with 5 to 10 key-values so that state is the key and its capital is the value. Print the dictionary and its length. b) Create and print a list of states and a list of capitals. c) Ask the user for a state's name. Check to see if the state's name exists in the list of states. If it does, look up the state's name in the dictionary and print out its capital. If...
You will have two functions: Function 1: update(user_dictionary): This function will take a dictionary entry as...
You will have two functions: Function 1: update(user_dictionary): This function will take a dictionary entry as user that has keys, ‘username’,’password’,’uid’, and ‘gid’ along with values. You will search if the username is already in your user_list that you get from your userfile.json file that you have created in your previous task. If the username in your user_dictionary is not in the list that is in your .json file then add the user_dictionary into the existing list and update your...
8) Write Python code for a function called occurances that takes two arguments str1 and str2,...
8) Write Python code for a function called occurances that takes two arguments str1 and str2, assumed to be strings, and returns a dictionary where the keys are the characters in str2. For each character key, the value associated with that key must be either the string ‘‘none’’, ‘‘once’’, or ‘‘more than once’’, depending on how many times that character occurs in str1. In other words, the function roughly keeps track of how many times each character in str1 occurs...
Create a function called, convert. This function receives a string parameter called word which only contains...
Create a function called, convert. This function receives a string parameter called word which only contains digits (the string represents a positive number) and returns a list of numbers. This is how the function works: - This function calculates the number of times each digit has repeated in the input string and then generates a number based on that using the following formula and adds it to a list. For instance, if the digit x has been repeated n times,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT