[Tutor] Fixing garbled email addresses
dotancohen at gmail.com
Tue May 1 16:43:51 CEST 2007
On 01/05/07, Ben Sherman <bensherman at gmail.com> wrote:
> Hey there - it would be better if you replied to the list - that way the
> answers below could help others..
> On 5/1/07, Dotan Cohen <dotancohen at gmail.com> wrote:
> > > # Then filter each line of the file through the regex, discarding the
> > > <> from above, and puts each address into a list.
> > > addresses = [re_mail.search(line).group(1) for line in
> > Alright, I had to read that line twice. That's fine, though, I'm just
> > getting started.
> This is a list comprehension - let's break it up so I can explain it a
> little better.
> # a new list
> addresses = 
> # read each line of the file
> for line in email_list.readline():
> # search each line, then print out what is in group 1 which is the text
> between the
> # parentheses in the compiled regex
> address = re_mail.search(line).group(1)
> # add the new address to out list
> List comprehensions are the best thing ever!
> Happy to help,
With Gmail one must be careful and check that the To and Subject
fields contain what you'd expect.
Does 'list comprehension' mean a detailed explanation of the code? If
so, then I'll be reading a lot of them in the near future. I really do
appreciate the dedication and attention to detail. Thanks.
More information about the Tutor