Last updated: 2025-02-06
This assignment is due February 22nd at 11:59 PM. Submit your solution on BrightSpace, under the “Unit 3” assignment.
Please copy your code into the text box, don’t submit a file. This will make it easier for me to grade.
You can submit multiple times. I will only grade your last submission.
This assignment uses the file guido_tweets.txt, which contains a list of tweets made by Guido van Rossum, the creator of the Python programming language. You can click on the filename to download the file. If it opens in your browser, can you use the shortcut Ctrl + S
(or Cmd + S
on macOS) to save the file to your computer.
Write a program in Python that performs the following tasks:
Print the following:
Expected output:
Number of tweets: 792
Tweet with max number of words: [Repeat so more people are aware of this]\\nPython 4 FAQ.\\n1. The version after 3.9 is 3.10; in fact it already exists (in github master).\\n2. If there ever is a version 4, the transition from 3 to 4 will be more like that from 1 to 2 rather than 2 to 3.
A username is a word that begins with the @
symbol (e.g., @MarkTwain
).
lower()
method) and remove all punctuation except for the @
symbolSample usage:
Enter username: gvanrossum
Not mentioned.
Enter username: @gvanrossum
Mentioned 15 times.
Enter username: dropbox
Not mentioned.
Enter username: @Dropbox
Not mentioned.
Enter username: Dropbox
Not mentioned.
Enter username: @dropbox
Mentioned 5 times.
Note that the lookup is case-sensitive, and requires the @
symbol to be included.
Your program’s final output should look something like the following:
Number of tweets: 792
Tweet with max number of words: [Repeat so more people are aware of this]\\nPython 4 FAQ.\\n1. The version after 3.9 is 3.10; in fact it already exists (in github master).\\n2. If there ever is a version 4, the transition from 3 to 4 will be more like that from 1 to 2 rather than 2 to 3.
Enter username: gvanrossum
Not mentioned.
Enter username: @gvanrossum
Mentioned 15 times.
Enter username: dropbox
Not mentioned.
Enter username: @Dropbox
Not mentioned.
Enter username: Dropbox
Not mentioned.
Enter username: @dropbox
Mentioned 5 times.
You should be able to do all of the tasks with only the Python topics we covered in class so far. However, if you want to try doing the homework in a more idiomatic (“Pythonic”) way, you could try the following questions in Google:
defaultdict
in Python?key
parameter of max
work in Python?The Python documentation may also be helpful: Python 3.10 documentation