Question: 1 . invert This is the first function you will write in dictionary.py . The other two functions will also be defined in this file.

1. invert
This is the first function you will write in dictionary.py. The other
two functions will also be defined in this file.
Given a dictionary of [str, str], invert should return a dict[str,
str] that inverts the keys and the values. The keys of the input list
becomes the values of the output list and vice versa.
Function name: invert
Parameter: dict[str, str]
Return Type: dict[str, str]
Remember that keys in a dictionary are unique. If you encounter more
than one of the same key when trying to invert your dictionary, raise
a KeyError. Example usage:
>>> invert({'a': 'z','b' : 'y','c': 'x'})
{'z': 'a','y': 'b','x': 'c'}
>>> invert({'apple': 'cat'})
{'cat': 'apple'}
>>> invert({'samuel': 'thompson', 'michael': 'thompson'})
KeyError
2. favorite colors
Create a function in your dictionary.py file called favorite_color. It
has the following specifications:
It takes as input a dict[str, str] of names and favorite colors.
It returns a str which is the color that appears most frequently.
If there is a tie for most popular color, return the color that
appeared in the dictionary first.
Function name: favorite_colors
Parameter: dict[str, str]- dictionary of names and favorite colors
Return Type: str - the most popular color
An example:
print(favorite_color({"Max": "yellow", "Eli": "blue", "Kara": "blue"}))
3. count
Given a list[str], this function will produce a dict[str, int] where
each key is a unique value in the given list and each value associated
is the count of the number of times that value appeared in the input
list.
Function name: count
Parameter: list[str]- list of values to count the frequencies of
Return Type: dict[str, int]- a dictionary of the counts of each of
the items in the input list
Implementation strategy:
Establish an empty dictionary to store your built-up result in
Loop through each item in the input list
Check to see if that item has already been established as a key in
your dictionary. Try the following boolean conditional: if in
: replacing with the variable name of the current value
and with the name of your result dictionary.
If the item is found in the dict, that means there is already a
key/value pair where the item is a key. Increase the value associated
with that key by 1(counting it!)
If the item is not found in the dict, that means this is the first
time you are encountering the value and should assign an initial count
of 1 to that key in the result dictionary.
Return the resulting dictionary.
4. alphabetizer
Given a list[str], this function will produce a dict[str, list[str]]
where each key is a unique letter in the alphabet and each value is a
list of the words that begin with that letter.
Function name: alphabetizer
Parameter: list[str]- list of words to categorize into different lists
Return Type: dict[str, list[str]]- a dictionary of the letters and
the lists of words that belong to that letter
Example usage:
>>> alphabetizer(["cat", "apple", "boy", "angry", "bad", "car"])
{'c': ['cat', 'car'],'a': ['apple', 'angry'],'b': ['boy', 'bad']}
>>> alphabetizer(["Python", "sugar", "Turtle", "party", "table"])
{'p': ['Python', 'party'],'s': ['sugar'],'t': ['Turtle', 'table']}
5. update_attendance
Given a dict[str, list[str]], this function will mutate and return
that dictionary. It should meet the following specifications:
It has three parameters:
dict[str, list[str]]- an existing dictionary that contains days of
the week as keys and a list of students who were in attendance as the
values
str - a day of the week
str - a student who attended class
Update the dict[str, list[str]] that was passed in with the new
attendance information, then return None.
An example:
attendance_log: dict ={"Monday": ["Samuel", "Kara"], "Tuesday": ["Michael"]}
update_attendance(attendance_log, "Tuesday" , "Samuel")
update_attendance(attendance_log, "Wednesday" , "Kara")
print(attendance_log)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!