On 01/05/07, Ben Sherman <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> wrote: > [snip] > > > > # 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 > email_list.readlines()] > > > > 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 > addresses.append(address) > > List comprehensions are the best thing ever! > > Happy to help, > Ben >
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. Dotan Cohen http://what-is-what.com/what_is/sitepoint.html http://u-tube-com.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor