Some objects are allowed as the second token in a for statement:
for each_var in obj:
These objects — i.e. the ones that can take the place of obj above are called iterables. A few iterables you’ve encountered thus far are strings, lists and tuples:
>>> for x in "dq": print(x)
>>> for x in ["d", "q"]: print(x)
>>> for x in ("d", "q"): print(x)
Any of these objects can be used inside a list comprehension even if they aren’t lists:
>>> print([x for x in "dq"])
>>> print([x for x in ("d", "q")])
This is simply a feature of list comprehensions, anything that can be used with a for loop can also be used in a list comprehension. You also have set and dictionary comprehensions, and they share this feature.
It just so happens that generators are iterables as well. This implies that you can use them as the second token in a for loop, and consequently that you can also use them inside comprehensions.
As a bonus, you can also have generator comprehensions:
>>> gen = (x for x in "dq")
And to confirm what was mentioned above, let’s use gen to create a list using list comprehension: