This is a question about Python internals. The following code is taken from this video about laziness in python: The sieve function generates prime numbers lazily (read this for the original concept). Conceptually, we add filters to the “sieve”, so every number (say, 10) is tested against all the previously found prime numbers (so 2, 3, 5 and 7) until
Tag: generator-expression
What type of iterable is “x for x in y”?
I’ve been confused of list comprehension in Python, although its shorthand doing for loop is very convenient. I’m not sure if what’s in the join() function’s parameter below is list comprehension since usually you put [] around to show it’s a list comprehension. My question: What’s the type of iterable produced by str(x) for x in res[::-1] in join() below?
Generator as function argument
Can anyone explain why passing a generator as the only positional argument to a function seems to have special rules? If we have: This works, as expected. This does not work, as expected. This works, as expected This works, but I don’t understand why. Shouldn’t it fail in the same way as 2) Answer Both 3. and 4. should be