This course will introduce the core data structure of the Python programming ... And, the answer is only for hint . it is helpful for those student who haven't submit Assignment and who confused ... These five lines are the lines to do this particular assignment where we are ...
chapter 9 week 5 quiz
Get link
Facebook
X
Pinterest
Email
Other Apps
chapter 9 week 5 quiz
chapter 9 week 5 quiz
Quiz
1 / 10
How are Python dictionaries different from Python lists?
Python lists store multiple values and dictionaries store a single value
Python lists are indexed using integers and dictionaries can use strings as indexes
Python dictionaries are a collection and lists are not a collection
Python lists can store strings and dictionaries can only store words
What is a term commonly used to describe the Python dictionary feature in other programming languages?
Closures
Associative arrays
Lambdas
Sequences
What would the following Python code print out? stuff = dict()
print(stuff['candy'])
The program would fail with a traceback
-1
candy
0
What would the following Python code print out? stuff = dict()
print(stuff.get('candy',-1))
0
The program would fail with a traceback
'candy'
-1
(T/F) When you add items to a dictionary they remain in the order in which you added them.
False
True
What is a common use of Python dictionaries in a program?
Building a histogram counting the occurrences of various strings in a file
Sorting a list of names into alphabetical order
Splitting a line of input into words using a space as a delimiter
Computing an average of a set of numbers
Which of the following lines of Python is equivalent to the following sequence of statements assuming that counts is a dictionary? if key in counts:
counts[key] = counts[key] + 1
else:
counts[key] = 1
counts[key] = counts.get(key,0) + 1
counts[key] = (key in counts) + 1
counts[key] = key + 1
counts[key] = (counts[key] * 1) + 1
In the following Python, what does the for loop iterate through? x = dict()
...
for y in x :
...
It loops through the keys in the dictionary
It loops through the values in the dictionary
It loops through the integers in the range from zero through the length of the dictionary
It loops through all of the dictionaries in the program
Which method in a dictionary object gives you a list of the values in the dictionary?
each()
all()
items()
values()
What is the purpose of the second parameter of the get() method for Python dictionaries?
An alternate key to use if the first key cannot be found
To provide a default value if the key is not found
9.4 Write a program to read through the mbox-short.txt and figure out who has sent the greatest number of mail messages. The program looks for 'From ' lines and takes the second word of those lines as the person who sent the mail. The program creates a Python dictionary that maps the sender's mail address to a count of the number of times they appear in the file. After the dictionary is produced, the program reads through the dictionary using a maximum loop to find the most prolific committer. Answer:
6.5 Write code using find() and string slicing (see section 6.10) to extract the number at the end of the line below. Convert the extracted value to a floating point number and print it out. Answer:
10.2 Write a program to read through the mbox-short.txt and figure out the distribution by hour of the day for each of the messages. You can pull the hour out from the 'From ' line by finding the time and then splitting the string a second time using a colon. From stephen.marquard@uct.ac.za Sat Jan 5 09 :14:16 2008 Once you have accumulated the counts for each hour, print out the counts, sorted by hour as shown below. Answer:
Comments
Post a Comment
if you have any doubt , please write comment