Generator Comprehensions

2018-07-09 Thread Steven D'Aprano
Based on feedback from people annoyed at having to write "comprehensions and generator expressions" to refer to what ought to be a single concept, Guido has given the thumbs up for a documentation change to start referring to "generator comprehensions". https://mail.

Re: loops -> list/generator comprehensions

2005-02-07 Thread Steven Bethard
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: Bizarr

Re: loops -> list/generator comprehensions

2005-02-07 Thread Caleb Hattingh
Wow, Steve, thanks, you went to some effort here. I prefer to give names to the values produced by os.walk -- I think it makes the usage much clearer. However, since I don't use 'dirnames', I use '_' to indicate this: Actually, I feel silly for not recognising this - I read about the Python3

Re: loops -> list/generator comprehensions

2005-02-06 Thread Steven Bethard
Alex Martelli wrote: Steven Bethard <[EMAIL PROTECTED]> 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.: [(dir

Re: loops -> list/generator comprehensions

2005-02-06 Thread Alex Martelli
Steven Bethard <[EMAIL PROTECTED]> 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.: [(dirp

Re: loops -> list/generator comprehensions

2005-02-06 Thread Steven Bethard
Caleb Hattingh wrote: filenames = [os.path.join(dirpath, filename) # This is cool for dirpath, _, filenames in os.walk('.') # This is getting tricky, whats the '_' for? Nothing to do with the list comprehension really. '_' is a commonly used variable name

Re: loops -> list/generator comprehensions

2005-02-06 Thread Caleb Hattingh
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

Re: loops -> list/generator comprehensions

2005-02-06 Thread Steven Bethard
On 6 Feb 2005 11:28:37 -0800, <[EMAIL PROTECTED]> wrote: > > walkList = [(x[0], x[2]) for x in os.walk(".")] > filenames = [] > for dir, files in walkList: > filenames.extend(["/".join([dir, f]) for f in files]) Caleb Hattingh top-posted: I would be interested to see an example

Re: loops -> list/generator comprehensions

2005-02-06 Thread jamesthiele . usenet
> HTH, It does. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: loops -> list/generator comprehensions

2005-02-06 Thread Caleb Hattingh
I would be interested to see an example of code that is more concise but yet as *clear* as the one you already have. I can actually read and understand what you've got there. That's cool :) On 6 Feb 2005 11:28:37 -0800, <[EMAIL PROTECTED]> wrote: I wrote this little piece of code to get a l

Re: loops -> list/generator comprehensions

2005-02-06 Thread Steven Bethard
[EMAIL PROTECTED] wrote: I wrote this little piece of code to get a list of relative paths of all files in or below the current directory (*NIX): walkList = [(x[0], x[2]) for x in os.walk(".")] filenames = [] for dir, files in walkList: filenames.extend(["/".join([dir, f]) for

loops -> list/generator comprehensions

2005-02-06 Thread jamesthiele . usenet
I wrote this little piece of code to get a list of relative paths of all files in or below the current directory (*NIX): walkList = [(x[0], x[2]) for x in os.walk(".")] filenames = [] for dir, files in walkList: filenames.extend(["/".join([dir, f]) for f in files]) It works f