loops -> list/generator comprehensions

Steven Bethard steven.bethard at gmail.com
Sun Feb 6 17:44:21 EST 2005


Alex Martelli wrote:
> Steven Bethard <steven.bethard at gmail.com> wrote:
> 
> 
>>at the OP's original code, the line:
>>
>> [(x[0], x[2]) for x in os.walk(".")]
>>
>>is the equivalent of:
>>
>> [dirpath, filenames for dirpath, dirnames, filenames in os.walk('.')]
> 
> 
> Just a nit: you need parentheses in your second LC too, i.e.:
> 
>  [(dirpath, filenames) for dirpath, dirnames, filenames in os.walk('.')]

Yup, you're right (of course) ;)  Thanks for the catch!

Steve



More information about the Python-list mailing list