Posts

Showing posts from June, 2020

chapter 10 week 6 Assignment 10.2

Image
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:

chapter 10 week 6 quiz

chapter 10 week 6 quiz Index => chapter 10 week 6 quiz Quiz Show all questions <=   => 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

chapter 9 week 5 Assignment 9.4

Image
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:

chapter 9 week 5 quiz

chapter 9 week 5 quiz Index => chapter 9 week 5 quiz Quiz Show all questions <=   => 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 prog