
In fact you also created a whole new subordinate data flow that doesn't exist in
Stephen J. Turnbull wrote: the original (the [x+1]). I bet that a complex
comprehension in your style will need to create a singleton iterable per source element for every mapping except the first.
I don't think so. Sounds like you missed that `for x in [x + 1]` is now treated as `x = x + 1` not only by humans but also by Python, see the first item here: https://docs.python.org/3/whatsnew/3.9.html#optimizations From disassembling my expression (in Python 3.10): Disassembly of <code object <listcomp> at 0x00000207F8D599A0, file "<dis>", line 1>: 1 0 BUILD_LIST 0 2 LOAD_FAST 0 (.0) >> 4 FOR_ITER 14 (to 34) 6 STORE_FAST 1 (x) 8 LOAD_FAST 1 (x) 10 LOAD_CONST 0 (1) 12 BINARY_ADD 14 STORE_FAST 1 (x) 16 LOAD_FAST 1 (x) 18 LOAD_CONST 1 (2) 20 BINARY_MODULO 22 LOAD_CONST 2 (0) 24 COMPARE_OP 2 (==) 26 POP_JUMP_IF_FALSE 2 (to 4) 28 LOAD_FAST 1 (x) 30 LIST_APPEND 2 32 JUMP_ABSOLUTE 2 (to 4) >> 34 RETURN_VALUE That's *more* efficient than your separate iterators having to interact, not less. I also tried timing it, with `source = [1,2,3] * 10**6`. Mine took 1.15 seconds to process that, yours took 1.75 seconds. Turning your outer one into a list comp got it to 1.58 seconds, still much slower.