Question

def count_data(d: dict) -> int: ''' Given d where the keys are [...fill this in...] and...

def count_data(d: dict) -> int:

'''

Given d where the keys are [...fill this in...] and values are

the number of occurrences of each key, return the total

number of occurrences being analyzed (including duplicates).

>>> count_data({'Jan': 4, 'Feb': 0, 'Mar': 1})

5

>>> count_data({'Jan': 0, 'Feb': 0, 'Mar': 25})

25

'''

pass

def most_common_key(d: dict) -> list:

'''

Given d representing the number of occurrences of each

key within the data set analyzed, give a list of the keys

that occur the most frequently.

Note: there could be multiple keys that occur

most frequently, which is why we're returning a list.

If there is only one most frequent key, the returned value

would just be a list of one element that is that key.

'''

pass

pls use python dictionary

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code for two functions:

def count_data(d: dict) -> int:

    '''

    Given d where the keys are [...fill this in...] and values are

    the number of occurrences of each key, return the total

    number of occurrences being analyzed (including duplicates).

    >>> count_data({'Jan': 4, 'Feb': 0, 'Mar': 1})

    5

    >>> count_data({'Jan': 0, 'Feb': 0, 'Mar': 25})

    25

    '''

    sum = 0

    for x in d:

        sum = sum + d.get(x)

    return sum

def most_common_key(d: dict) -> list:

    '''

    Given d representing the number of occurrences of each

    key within the data set analyzed, give a list of the keys

    that occur the most frequently.

    Note: there could be multiple keys that occur

    most frequently, which is why we're returning a list.

    If there is only one most frequent key, the returned value

    would just be a list of one element that is that key.

    '''

    li = []

     # All elements having value more than thresholdValue will

        # added to the list

    thresholdValue = 15

    for x in d:

        if d.get(x) >= thresholdValue :

            li.append(x)

    return li

Image and Output:


Add a comment
Know the answer?
Add Answer to:
def count_data(d: dict) -> int: ''' Given d where the keys are [...fill this in...] and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Help me with this Python Question a. build_word_dictionary (filename) – This builds a word dictionary indexed...

    Help me with this Python Question a. build_word_dictionary (filename) – This builds a word dictionary indexed by words from the file who’s filename is provided as an argument. It uses the words as keys and the count of occurrences as values. It returns the dictionary it constructed. It can use the ‘tokenize()’ function that is provided in the lecture slides. b. inverse_dict(dict) – This method takes a dictionary (generated by build_word_dictionary() and inverts it (as was done with students and...

  • def check_items(current_location, game_items, inventory): ''' (float, dict, list) -> None    Given a float location id...

    def check_items(current_location, game_items, inventory): ''' (float, dict, list) -> None    Given a float location id and a dict of game items, check if any of the game items are found in the current location provided. If they are, add them to the inventory that's provided. The game_items dict has item names as keys, and values as lists with the following information in this order: [description of item, location ID of where the item is found, location ID of where...

  • class Livestock: def __init__(self,name,price_in,utilizations): self.name,self.price_in,self.utilizations = name,float(price_in),utilizations def __lt__(self,other): if self.utilizations is None: return True elif...

    class Livestock: def __init__(self,name,price_in,utilizations): self.name,self.price_in,self.utilizations = name,float(price_in),utilizations def __lt__(self,other): if self.utilizations is None: return True elif other.utilizations is None: return False else: return self.utilizations.count(';') < other.utilizations.count(';') def __eq__(self,other): return self.name == other.name def __repr__(self): return ("{}, {}".format(self.name,self.price_in)) raw_livestock_data = [ # name, price_in, utilizations ['Dog', '200.0', 'Draught,Hunting,Herding,Searching,Guarding.'], ['Goat', '1000.0', 'Dairy,Meat,Wool,Leather.'], ['Python', '10000.3', ''], ['Cattle', '2000.75', 'Meat,Dairy,Leather,Draught.'], ['Donkey', '3400.01', 'Draught,Meat,Dairy.'], ['Pig', '900.5', 'Meat,Leather.'], ['Llama', '5000.66', 'Draught,Meat,Wool.'], ['Deer', '920.32', 'Meat,Leather.'], ['Sheep', '1300.12', 'Wool,Dairy,Leather,Meat.'], ['Rabbit', '100.0', 'Meat,Fur.'], ['Camel', '1800.9', 'Meat,Dairy,Mount.'], ['Reindeer', '4000.55', 'Meat,Leather,Dairy,Draught.'],...

  • def do_action(decision, game_data, current_location, inventory): ''' (int, dict, float, list) -> str Given the game data...

    def do_action(decision, game_data, current_location, inventory): ''' (int, dict, float, list) -> str Given the game data dict, and the current location ID, get all the possible actions at that location. If the decision number given as 'decision' falls outside the number of allowed actions at this location, then return the string "Invalid decision. Please select choice from the decisions listed." Make sure this string is EXACTLY as above. Else, if the decision is valid, then figure out the location information...

  • Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can...

    Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can be solved in one post so I posted the other on another question so please check them out as well :) Here is the questions in this assignment: Note: Two helper functions Some of the testing codes for the functions in this assignment makes use of the print_dict in_key_order (a dict) function which prints dictionary keyvalue pairs...

  • using python Write a function that takes a dictionary and a list of keys as 2...

    using python Write a function that takes a dictionary and a list of keys as 2 parameters. It removes the entries associated with the keys from the given dictionary Your function should not print or return anything. The given dictionary should be modified after the function is called Note: it means that you can't create another dictionary in your function. Since dictionaries are mutable, you can modify them directly def remove_keys (dict, key_list) "" "Remove the key, value pair from...

  • Hey guys I need help with this question: # 4444444444444444444444444444444444444444444444444 # get-triples-dict() Define the get triples...

    Hey guys I need help with this question: # 4444444444444444444444444444444444444444444444444 # get-triples-dict() Define the get triples diet) funetion which is passed a string of text as a The function first converts the parameter string to lower case turns a dictionary with keys which are all the unique consecutive tic characters from the text, and the corresponding values are characters appear in parameter. and then re three alphabe the number of times the three consecutive alphabetic text. Use the isalpha() method...

  • Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti s...

    Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti synonyms function which is passed a dictionary as a parameter- The keys of the parameter dictionary are words and the corresponding values are 1ists of synonyms (synonyms are words which have the same or nearly the same meaning). The function romoves all the eynonyme which have ous than 8 charactors from each corresponding list of synonyms-As well, the funet...

  • package hw3; import java.util.LinkedList; /* *********************************************************************** * A simple BST with int keys and no values...

    package hw3; import java.util.LinkedList; /* *********************************************************************** * A simple BST with int keys and no values * * Complete each function below. * Write each function as a separate recursive definition (do not use more than one helper per function). * Depth of root==0. * Height of leaf==0. * Size of empty tree==0. * Height of empty tree=-1. * * TODO: complete the functions in this file. * DO NOT change the Node class. * DO NOT change the name...

  • This script will create a dictionary whose keys are all the directories listed in thePATH system...

    This script will create a dictionary whose keys are all the directories listed in thePATH system variable, and whose values are the number of files in each of these directories. The script will also print each directory entry sorted by directory name. The script will use the following five functions to get the required results get_environment_variable_value() get_dirs_from_path() get_file_count() get_file_count_for_dir_list() print_sorted_dictionary() get_environment_variable_value() The header for this function must be This function must accept a shell variable as its only parameter The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT