Update (I need to rephrase this)
I'm trying to do the following:
Write a program that downloads and counts the total number of words in 'https://ift.tt/2thmVy4'.
However, I'm not sure how to do that. I have the following working code:
fhand = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
for line in fhand:
print(line.decode().strip())
The above will download the 4 lines. I need to be able to download it as well as get the count which is 33.
Is there a way to do both tasks at the same time within the code? My professor gave me the following:
import urllib.parse, urllib.request, urllib.error
import re
url = "http://data.pr4e.org/romeo.txt"
I feel there's a clue where I have to use re but not sure how to apply it to this problem.
Aucun commentaire:
Enregistrer un commentaire