There is no such thing as "tuple comprehension". This
Read Generator expressions and list comprehensions and also PEP-0289 for more details.
That said, you need to know that in python 3
you can do
in any case this will never be
(x for x in range(100000000))
is generator expression.Read Generator expressions and list comprehensions and also PEP-0289 for more details.
That said, you need to know that in python 3
range()
is lazy and will return range
object, i.e. range(100000000)
will produce range
object and it will be consumed when needed, not generate all numbers in memory (like in python2, where we have lazy xrange()
). So basically you create [lazy] generator from lazy range objectyou can do
list(range(100000000))
, set(range(100000000))
and tuple(range(100000000))
to produce list, set or tuple respectively.(Aug-10-2021, 03:28 AM)quazirfan Wrote: Why not instantiate it during creation? For example, why not treat (x for x in range(10)) as (10, 10, 10, 10, 10, 10, 10, 10, 10, 10)
in any case this will never be
(10, 10, 10, 10, 10, 10, 10, 10, 10, 10)
. it will be (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
if it was a tuple and not generator expression...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs