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.
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 dictstr
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: dictstr str
Return Type: dictstr 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:
inverta: zb : yc: x
z: ay: bx: c
invertapple: 'cat'
cat: 'apple'
invertsamuel: 'thompson', 'michael': 'thompson'
KeyError
favorite colors
Create a function in your dictionary.py file called favoritecolor. It
has the following specifications:
It takes as input a dictstr 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: favoritecolors
Parameter: dictstr str dictionary of names and favorite colors
Return Type: str the most popular color
An example:
printfavoritecolorMax: "yellow", "Eli": "blue", "Kara": "blue"
count
Given a liststr this function will produce a dictstr 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: liststr list of values to count the frequencies of
Return Type: dictstr int a dictionary of the counts of each of
the items in the input list
Implementation strategy:
Establish an empty dictionary to store your builtup 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
keyvalue pair where the item is a key. Increase the value associated
with that key by 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 to that key in the result dictionary.
Return the resulting dictionary.
alphabetizer
Given a liststr this function will produce a dictstr liststr
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: liststr list of words to categorize into different lists
Return Type: dictstr liststr a dictionary of the letters and
the lists of words that belong to that letter
Example usage:
alphabetizercat "apple", "boy", "angry", "bad", "car"
c: cat 'car'a: apple 'angry'b: boy 'bad'
alphabetizerPython "sugar", "Turtle", "party", "table"
p: Python 'party's: sugart: Turtle 'table'
updateattendance
Given a dictstr liststr this function will mutate and return
that dictionary. It should meet the following specifications:
It has three parameters:
dictstr liststr 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 dictstr liststr that was passed in with the new
attendance information, then return None.
An example:
attendancelog: dict Monday: Samuel "Kara" "Tuesday": Michael
updateattendanceattendancelog "Tuesday" "Samuel"
updateattendanceattendancelog "Wednesday" "Kara"
printattendancelog
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
