Assignment2 Part2
Assignment2 Part2
The dictionary Junior shows a schedule for a junior year semester. The key is the course name
and the value is the number of credits. Find the total number of credits taken this semester and
assign it to the variable credits . Do not hardcode this – use dictionary accumulation!
In [1]:
Junior = {'SI 206':4, 'SI 310':4, 'BL 300':3, 'TO 313':3, 'BCOM 350':1, 'MO 300':3}
credits = None
credits = sum(Junior.values())
18
In [2]:
Grade cell: cell-c8fa510d6d4f279a Score: 1.0 / 1.0 (Top)
Create a dictionary, freq , that displays each character in string str1 as the key and its frequency
as the value.
https://www.coursera.org/api/rest/v1/executorruns/richfeedback?id=AY7MUZ4HEe-AEBJMcgTSCQ&feedbackType=HTML 1/9
11/12/24, 8:53 PM assignment2_part2
In [3]:
{'p': 9, 'e': 8, 't': 1, 'r': 3, ' ': 7, 'i': 3, 'c': 3, 'k': 3, 'd': 2, 'a': 1, 'o':
In [4]:
Provided is a string saved to the variable name s1 . Create a dictionary named counts that
contains each letter in s1 and the number of times it occurs.
https://www.coursera.org/api/rest/v1/executorruns/richfeedback?id=AY7MUZ4HEe-AEBJMcgTSCQ&feedbackType=HTML 2/9
11/12/24, 8:53 PM assignment2_part2
In [5]:
s1 = 'hello'
counts = {}
In [6]:
Create a dictionary, freq_words , that contains each word in string str1 as the key and its
frequency as the value.
https://www.coursera.org/api/rest/v1/executorruns/richfeedback?id=AY7MUZ4HEe-AEBJMcgTSCQ&feedbackType=HTML 3/9
11/12/24, 8:53 PM assignment2_part2
In [7]:
str1 = 'I wish I wish with all my heart to fly with dragons in a land apart'
#str1 = 'I wish I wish with all my heart to fly with dragons in a land apart'
In [8]:
Create a dictionary called wrd_d from the string sent , so that the key is a word and the value is
how many times you have seen that word.
https://www.coursera.org/api/rest/v1/executorruns/richfeedback?id=AY7MUZ4HEe-AEBJMcgTSCQ&feedbackType=HTML 4/9
11/12/24, 8:53 PM assignment2_part2
In [9]:
sent = 'Singing in the rain and playing in the rain are two entirely different situ
wrd_d = {}
In [10]:
Create the dictionary characters that shows each character from the string sally and its
frequency. Then, find the most frequent letter based on the dictionary. Assign this letter to the
variable best_char .
https://www.coursera.org/api/rest/v1/executorruns/richfeedback?id=AY7MUZ4HEe-AEBJMcgTSCQ&feedbackType=HTML 5/9
11/12/24, 8:53 PM assignment2_part2
In [11]:
{'s': 8, 'a': 3, 'l': 6, 'y': 2, ' ': 7, 'e': 6, 'h': 3, 'b': 1, 't': 1, 'o': 1, 'r':
The most frequent character is: s
In [12]:
Find the least frequent letter. Create the dictionary characters that shows each character from
string sally and its frequency. Then, find the least frequent letter in the string and assign the letter
to the variable worst_char .
https://www.coursera.org/api/rest/v1/executorruns/richfeedback?id=AY7MUZ4HEe-AEBJMcgTSCQ&feedbackType=HTML 6/9
11/12/24, 8:53 PM assignment2_part2
In [13]:
sally = 'sally sells sea shells by the sea shore and by the road'
characters = {}
# Find the character with the lowest frequency (ignore spaces or other characters if
worst_char = min(characters, key=characters.get)
{'s': 8, 'a': 5, 'l': 6, 'y': 3, ' ': 11, 'e': 7, 'h': 4, 'b': 2, 't': 2, 'o': 2, 'r'
The least frequent character is: n
In [14]:
Create a dictionary named letter_counts that contains each letter and the number of times it
occurs in string1 .
Challenge: Letters should not be counted separately as upper-case and lower-case. Intead, all of
them should be counted as lower-case.
https://www.coursera.org/api/rest/v1/executorruns/richfeedback?id=AY7MUZ4HEe-AEBJMcgTSCQ&feedbackType=HTML 7/9
11/12/24, 8:53 PM assignment2_part2
In [15]:
string1 = "There is a tide in the affairs of men, Which taken at the flood, leads o
letter_counts = {}
{'t': 19, 'h': 11, 'e': 29, 'r': 12, 'i': 14, 's': 15, 'a': 17, 'd': 7, 'n': 15, 'f':
In [16]:
Grade cell: cell-d01025e4e9d1d5d4 Score: 1.0 / 1.0 (Top)
Create a dictionary called low_d that keeps track of all the characters in the string p and notes
how many times each character was seen. Make sure that there are no repeats of characters as
keys, such that “T” and “t” are both seen as a “t” for example.
https://www.coursera.org/api/rest/v1/executorruns/richfeedback?id=AY7MUZ4HEe-AEBJMcgTSCQ&feedbackType=HTML 8/9
11/12/24, 8:53 PM assignment2_part2
In [17]:
p = "Summer is a great time to go outside. You have to be careful of the sun though
low_d = {}
{'s': 5, 'u': 7, 'm': 3, 'e': 12, 'r': 3, 'i': 3, 'a': 6, 'g': 3, 't': 9, 'o': 8, 'd'
In [18]:
Grade cell: cell-642520e26103eb1b Score: 1.0 / 1.0 (Top)
https://www.coursera.org/api/rest/v1/executorruns/richfeedback?id=AY7MUZ4HEe-AEBJMcgTSCQ&feedbackType=HTML 9/9