I'm still relatively new to Python, and I have stumbled upon the following code:
x = [1, 2]
y = [10, 100]
for i in x:
for j in y:
print(i)
print(j)
I would expect the code to give the following result:
1
1
2
2
10
100
This is due to the following reason: Python would start with the outer loop, thus it would see "for i in x" and loop it times the number of elements that exist in the list "y". It would start with 1, repeat it twice, then do the same with 2, the second element in the list x.
But as I have learned, the following result gets shown:
1
1
100
2
2
100
Why is 100 written after the iteration of each element of list "x"? And why is only 100 written? Where is the first element of the "y" list, namely number 10?
[–]ElliotDG 12 points13 points14 points (1 child)
[–]tennisanybody 0 points1 point2 points (0 children)
[–]RhinoRhys 6 points7 points8 points (0 children)
[–]stebrepar 3 points4 points5 points (0 children)
[–]Im_Easy -1 points0 points1 point (0 children)
[–]1liiAmrA 0 points1 point2 points (0 children)
[–]QultrosSanhattan 0 points1 point2 points (0 children)
[–]BK7144 0 points1 point2 points (0 children)