loops -> list/generator comprehensions
Steven Bethard
steven.bethard at gmail.com
Mon Feb 7 15:59:15 EST 2005
Caleb Hattingh wrote:
>> Would
>>
>> filenames = [os.path.join(dirpath, filename)
>> for dirpath, dirnames, filenames in os.walk('.')
>> for filename in filenames]
>>
>> have been clearer for you? Then all you have to do is remember the
>> order of the for-loop execution:
>
> Bizarre as this may sound, it was the '_' that was throwing me off the
> whole thing (at the 'grok' level I generally read the newsgroup,
> anyway). For some weird reason, I can read *this* comprehension
> pretty easily! Does that make sense at all? I figure a little bit of
> uncertainty along the way probably derails understanding of the whole
> thing a little bit
Yup, actually, that's what I kinda suspected happened. But if it
happened for you, it probably happened for a dozen other folks who read
the same thing, so I'm glad to hear rewriting it and explaining the '_'
was helpful.
STeVe
More information about the Python-list
mailing list