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 10 week 6 quiz
Get link
Facebook
X
Pinterest
Email
Other Apps
chapter 10 week 6 quiz
chapter 10 week 6 quiz
Quiz
1 / 10
What is the difference between a Python tuple and Python list?
Lists are mutable and tuples are not mutable
Lists are indexed by integers and tuples are indexed by strings
Lists maintain the order of the items and tuples do not maintain order
Tuples can be expanded after they are created and lists cannot
Which of the following methods work both in Python lists and Python tuples?
sort()
append()
pop()
index()
What will end up in the variable y after this code is executed? x , y = 3, 4
A two item list
A dictionary with the key 3 mapped to the value 4
A two item tuple
4
In the following Python code, what will end up in the variable y? x = { 'chuck' : 1 , 'fred' : 42, 'jan': 100}
y = x.items()
A list of strings
A tuple with three integers
A list of tuples
A list of integers
Which of the following tuples is greater than x in the following Python sequence? x = (5, 1, 3)
if ??? > x :
...
(4, 100, 200)
(0, 1000, 2000)
(6, 0, 0)
(5, 0, 300)
What does the following Python code accomplish, assuming the c is a non-empty dictionary? tmp = list()
for k, v in c.items() :
tmp.append( (v, k) )
It computes the largest of all of the values in the dictionary
It sorts the dictionary based on its key values
It creates a list of tuples where each tuple is a value, key pair
It computes the average of all of the values in the dictionary
If the variable data is a Python list, how do we sort it in reverse order?
data = sortrev(data)
data = data.sort(-1)
data.sort.reverse()
data.sort(reverse=True)
Using the following tuple, how would you print 'Wed'? days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
print(days[1])
print(days(2))
print(days.get(1,-1))
print(days[2])
In the following Python loop, why are there two iteration variables (k and v)? c = {'a':10, 'b':1, 'c':22}
for k, v in c.items() :
...
Because the keys for the dictionary are strings
Because there are two items in the dictionary
Because the items() method in dictionaries returns a list of tuples
Because for each item we want the previous and current key
Given that Python lists and Python tuples are quite similar - when might you prefer to use a tuple over a list?
For a temporary variable that you will use and discard without modifying
For a list of items that want to use strings as key values instead of integers
For a list of items that will be extended as new items are 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