I'll explain with an example.
Let's say that you've got some existing nested for-loop that you want to inline:
for bytestring in x:
for i in bytestring:
for k in reversed(range(8)):
yield ((i & (0b1 << k)) >> k)
Intuitively, you might think that you would type something like "bit for k in bits for bits in in bytes for bytes in x" — but this is wrong.
Instead, you must leave the for
s in the same order as in the code-block form, only popping the inner expression itself to the front:
iter( ((i & (0b1 << k)) >> k) for bytestring in x for i in bytestring for k in reversed(range(8)) )