The best source of information is the official official Python list recognition tutorial . List mappings are almost the same as for loops (of course, any understanding of the list can be written as a for loop), but they are often faster than using a for loop.
Take a look at this longer list comprehension from the tutorial (the if part filters the comprehension, only those parts that pass the if statement are passed to the final part of the list comprehension (here (x,y) ):
>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y] [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
This is exactly the same as this nested loop loop (and, as the tutorial says, notice how the for and if order are the same).
>>> combs = [] >>> for x in [1,2,3]: ... for y in [3,1,4]: ... if x != y: ... combs.append((x, y)) ... >>> combs [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
The main difference between understanding a list and a for loop is that the end of the for loop (where you do something) happens at the beginning, not the end.
To your questions:
What type must be an object to use this for loop structure?
An iterable . Any object that can generate a (finite) set of elements. These include any container, lists, sets, generators, etc.
What is the order in which i and j are assigned to elements in an object?
They are assigned exactly in the order in which they are generated from each list, as if they were in a nested loop (for your first understanding, you get 1 element for i, then each value from j, the 2nd element in i, then each value from j, etc.)
Is it possible to simulate a different loop structure?
Yes, already shown above.
Could this for a loop be nested with a similar or different structure for the loop? And what would it look like?
Of course, but this is not a great idea. Here, for example, you get a list of character lists:
[[ch for ch in word] for word in ("apple", "banana", "pear", "the", "hello")]