+ 1

How does nested for loop work, 2,3,4

27th Jan 2020, 4:11 PM
Microne mafika
Microne mafika - avatar
5 odpowiedzi
+ 1
for x in list1: for y in list2: print(str(x) +str(y)
27th Jan 2020, 4:31 PM
Oma Falk
Oma Falk - avatar
+ 6
Nested for loop means, that inside an 'outer' for loop, an 'inner' for loop is running. Sample: l1 = ['a','b','c'] l2 = [1, 2, 3] for outer in l1: # outer loop for inner in l2: # inner loop print(f'{outer}{inner}', end= ', ') # output: a1, a2, a3, b1, b2, b3, c1, c2, c3, As you can see the first outer value is taken, and then a complete iteration on the inner loop is done. Then next outer value and again a complete iteration on inner loop is done, and so on...
27th Jan 2020, 4:25 PM
Lothar
Lothar - avatar
+ 2
could u clarify what u mean please?
27th Jan 2020, 4:23 PM
Oma Falk
Oma Falk - avatar
+ 1
If you need help, you can post the code you're struggling with! https://www.sololearn.com/post/75089/?ref=app
27th Jan 2020, 4:25 PM
Scooby
Scooby - avatar