On 2017-08-07 08:35 PM, Steven D'Aprano wrote:
Hi Soni, and welcome!
On Mon, Aug 07, 2017 at 04:30:05PM -0300, Soni L. wrote:
What if, (x for x in integers if 1000 <= x < 1000000), was syntax sugar
for (x for x in range(1000, 1000000))?
If you want the integers from 1000 to 1000000, use:
range(1000, 1000000)
Don't waste your time slowing down the code with an unnecessary and
pointless wrapper that does nothing but pass every value on unchanged:
(x for x in range(1000, 1000000)) # waste of time and effort
Actually, those have different semantics!
>>> x = range(1, 10)
>>> list(x)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(x)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> x = (x for x in range(1, 10))
>>> list(x)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(x)
[]
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/