loops -> list/generator comprehensions

Caleb Hattingh caleb1 at telkomsa.net
Sun Feb 6 23:34:32 EST 2005


Sure Steve

Lemme see ... (indentation changed so comments associate with correct bits)

> Out of curiosity, do you find:
>
> filenames = [os.path.join(dirpath, filename)
                       # This is cool
              for dirpath, _, filenames in os.walk('.')
              # This is getting tricky, whats the '_' for?  Which thing  
goes where again in a comprehension?
                        for filename in filenames]
                        # The hierarchy has nailed me by this point.  I  
will have to start over...

Yes, yes I do find it more difficult to read.  Maybe I just don't know  
python as well as I should (certainly not as well as others here!).  I  
guess it is just familiarity.  A single comprehension is ok, nesting them  
gets tricky, and 3 times is a strike for me.  I will practise :)

keep well
Caleb






More information about the Python-list mailing list