On 8/1/2015 12:00 PM, Ltc Hotspot wrote:
Hi Everyone:
Let me repost the question:
You will parse the From line using split() and print out the second word in
the line (i.e. the entire address of the person who sent the message). Then
print out a count at the end.
*Hint:* make sure not to include the lines that start with 'From:'.
You can download the sample data at
http://www.pythonlearn.com/code/mbox-short.txt
Cool - thanks. That's an mbox file.
Can you explain the apparent dichotomy of the question directing you to
'parse the from line' and the hint? I'm going to guess they mean that
you're not to print that line in the output? Aah, I see -- there're two
different lines that start From -- both with and without a trailing
colon. So then, we can split on 'From ' and recognizing the split eats
the split-on portion
>>> '1234567'.split('4')
['123', '567']
... and leaves an empty entry when splitting on the first characters of
the line
>>> '1234567'.split('1')
['', '234567']
... we get to:
for addr in [ fromline.split()[0]
for fromline in mbox.split('From ')
if fromline ]:
print addr
stephen.marqu...@uct.ac.za
lo...@media.berkeley.edu
zq...@umich.edu
rjl...@iupui.edu
zq...@umich.edu
rjl...@iupui.edu
c...@iupui.edu
gsil...@umich.edu
gsil...@umich.edu
zq...@umich.edu
gsil...@umich.edu
wagne...@iupui.edu
zq...@umich.edu
antra...@caret.cam.ac.uk
gopal.ramasammyc...@gmail.com
david.horw...@uct.ac.za
david.horw...@uct.ac.za
stephen.marqu...@uct.ac.za
lo...@media.berkeley.edu
lo...@media.berkeley.edu
r...@media.berkeley.edu
c...@iupui.edu
c...@iupui.edu
c...@iupui.edu
>>>
Emile
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor