Re: Different behaviour in list comps and generator expressions

2014-11-17 Thread Ethan Furman
On 11/17/2014 03:38 PM, Dan Stromberg wrote: > > 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? It's n

Re: Different behaviour in list comps and generator expressions

2014-11-17 Thread Dan Stromberg
On Mon, Nov 17, 2014 at 3:30 PM, Steven D'Aprano 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 t

Re: Different behaviour in list comps and generator expressions

2014-11-17 Thread Steven D'Aprano
Steven D'Aprano 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 Wol

Re: Different behaviour in list comps and generator expressions

2014-11-08 Thread Wolfgang Maier
On 08.11.2014 22:31, Wolfgang Maier wrote: On 08.11.2014 02:50, Steven D'Aprano 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 raise

Re: Different behaviour in list comps and generator expressions

2014-11-08 Thread Wolfgang Maier
On 08.11.2014 02:50, Steven D'Aprano 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. Generator expressions con

Re: Different behaviour in list comps and generator expressions

2014-11-07 Thread Roy Smith
In article <545d76fe$0$12980$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano 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

Different behaviour in list comps and generator expressions

2014-11-07 Thread Steven D'Aprano
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. Generator expressions consume them and halt, while comprehensions allow