Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017年11月23日 00:19:06 -0800

Ivan Levkivskyi wrote:
On 23 November 2017 at 05:44, Greg Ewing <[email protected] <mailto:[email protected]>> wrote:
 def g():
 return ((yield i) for i in range(10))
I think this code should be just equivalent to this code
 def g():
 temp = [(yield i) for i in range(10)]
 return (v for v in temp)
But then you get a non-lazy iterable, which defeats the
purpose of using a generator expression -- you might as
well have used a comprehension to begin with.
--
Greg
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to