Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80988
| References | <545d76fe$0$12980$c3e8da3$5496439d@news.astraweb.com> <546a8524$0$12990$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2014-11-17 15:38 -0800 |
| Subject | Re: Different behaviour in list comps and generator expressions |
| From | Dan Stromberg <drsalists@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15964.1416267547.18130.python-list@python.org> (permalink) |
On Mon, Nov 17, 2014 at 3:30 PM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: >> The following list comprehension and generator expression are almost, but >> not quite, the same: >> >> [expr for x in iterable] >> >> list(expr for x in iterable) >> >> >> The difference is in the handling of StopIteration raised inside the expr. > [...] > > > Thanks to Roy and Wolfgang for their comments. > > If anyone is interested, Guido will soon be ruling on a PEP which will > change the behaviour of generators and generator expressions, and he has > asked for feedback. In particular, examples of code which will be broken by > this change. > > Read the PEP here: > > https://www.python.org/dev/peps/pep-0479 > > > If you post comments here, I will see that they get forwarded on. I'm inclined to say that list comprehensions and generator expressions should be different. I don't really think they should be identical, one being eager and one being lazy. Why let the implementation detail of one impact the other?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Different behaviour in list comps and generator expressions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-08 12:50 +1100
Re: Different behaviour in list comps and generator expressions Roy Smith <roy@panix.com> - 2014-11-07 23:39 -0500
Re: Different behaviour in list comps and generator expressions Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-11-08 22:31 +0100
Re: Different behaviour in list comps and generator expressions Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-11-08 23:42 +0100
Re: Different behaviour in list comps and generator expressions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-18 10:30 +1100
Re: Different behaviour in list comps and generator expressions Dan Stromberg <drsalists@gmail.com> - 2014-11-17 15:38 -0800
Re: Different behaviour in list comps and generator expressions Ethan Furman <ethan@stoneleaf.us> - 2014-11-17 18:20 -0800
csiph-web