Question

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 no other built-in function or method]

Examples:      

              words = [“blue”, “blue”, “red”, “yellow”, “yellow”, “brown”, “Blue”]

              print(build_dictionary(words))

              returns:

              {‘blue’: 3, ‘red’:1, ‘yellow’:2, ‘brown’:1}

Homework Answers

Answer #1

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

def build_dictionary(words):
    d = {}
    count = 0
    for i in words:
        i = i.lower()
        for j in words:
            j = j.lower()
            if i == j:
                count += 1
        d.update({i: count})
        count = 0
    return d


words = ["blue", "blue", "red", "yellow", "yellow", "brown", "Blue"]

print(build_dictionary(words))
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
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 =...
Implement in python a function avg_val(lst), which returns the average value of the elements in list....
Implement in python a function avg_val(lst), which returns the average value of the elements in list. For example, given a list lst: [19, 2, 20, 1, 0, 18], the function should return 10. The name of the method should be avg_val and the method should take one parameter which is the list of values to test. Here is an example call to the function print(avg_val([19, 2, 20, 1, 0, 18]))
Write the function most_factors(numbers) that returns the integer from the list numbers that has the most...
Write the function most_factors(numbers) that returns the integer from the list numbers that has the most factors (divisors without remainder). For example: >>> most_factors([5,10,16,20,25]) 20 # because 20 has the most factors of any of these numbers # 6 factors, i.e., [1, 2, 4, 5, 10, 20] >>> most_factors([1, 2, 3, 4, 5]) 4 # because 4 has the most factors of any of these numbers # 3 factors, i.e., [1, 2, 4] Hints: For each element in numbers, call...
python 3 For this exercise you are to implement the function poly_iter in the array-backed list...
python 3 For this exercise you are to implement the function poly_iter in the array-backed list class, which, when called with positive integer parameters a, b, c, returns an iterator over the values in the underlying list at indexes a*i2+b*i+c, for i=0, 1, 2, ... E.g., given an array-backed list lst containing the elements [0, 1, 2, 3, 4, ..., 98, 99], the following code: for x in lst.poly_iter(2, 3, 4): print(x) will produce the output: 4 9 18 31...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are resolved using separate chaining. The hash table will store objects of the class Data. You will decide on the size of the table, keeping in mind that the size of the table must be a prime number. A table of size between 5000-10000, should work well. You must design your hash function so that it produces few collisions. A bad hash function that induces...
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
Develop a C++ PROGRAM which will find a hidden sentence in a list of random words...
Develop a C++ PROGRAM which will find a hidden sentence in a list of random words using map function Open this text file named shuffled_words.txt in your program If it matters, you may presume there are an even number of words in the file Place the contents of the file into an appropriate data structure in the following manner: Grab a pair of strings from the file (unless end of file is reached) Each string is separated by a space...
Python 3 Implement the function condense, which takes a "passage" (a string containing multiple sentences separated...
Python 3 Implement the function condense, which takes a "passage" (a string containing multiple sentences separated by the '\n' character), and returns a condensed version of that passage based on the following logic: the frequency with which each word appears in the entire passage is computed a score for each sentence in the passage is computed by summing the frequency of each word in the sentence the sentences with the top 3 scores (we assume there are no ties) are...
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question....
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question. Thank you! Here’s the contents of a file called example.cpp: // example.cpp #include "LinkedList.h" #include <iostream> #include <string> using namespace std; int main() { cout << "Please enter some words (ctrl-d to stop):\n"; LinkedList lst; int count = 0; string s; while (cin >> s) { count++; lst.add(remove_non_letters(s)); } // while cout << "\n" << count << " total words read in\n"; cout <<...
The main goal is to implement two recursive methods, each is built to manipulate linked data...
The main goal is to implement two recursive methods, each is built to manipulate linked data structures. To host these methods you also have to define two utterly simplified node classes. 1.) Add a class named BinaryNode to the project. This class supports the linked representation of binary trees. However, for the BinaryNode class Generic implementation not needed, the nodes will store integer values The standard methods will not be needed in this exercise except the constructor 2.) Add a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT