I'm adding another answer because no one has explained why this code doesn't work. Which seems to me what the OP was actually looking for.
Your Solution 1:
for i in list_a:
#This indentation is inside 'i' loop
for j in list_b:
#This indentation is inside 'j' loop
print(str(i) + str(j))
Will step through list_a
, and for every iteration, step through all of list_b
(as there's nothing in the list_b
code block, nothing will happen for each step) THEN print, so it will print out for every i
in list_a
and j
will always be the number of the last item of list_b
as it's stepped through the whole thing.
Although this code probably will not run anyway as there is an empty code block and the compiler will likely pick that up with an IndentationError
Your Solution 2:
for i in list_a:
for j in list_b:
print(str(i) + str(j))
Will step through all of list_a
and for each element, step through all of list_b
so you will end up with A1B1
, A1B2
, A1B3
, etc`.
Preferred Solution
The solution is to step through both lists at the same time, at the same rate which this answer covers nicely, with essentially the same solution as @Pavlins answer.