+ 2

Double loops inside list.

Please explain the output of this code: https://code.sololearn.com/c8pHPZxYUfi1/?ref=app

1st Jun 2020, 8:13 AM
Tricker
3 odpowiedzi
+ 4
You will get a list of lists. You will get a list at each iteration with the values [a,b]. for a in range(0,2): for b in range(0,2): When a is 0, the inner loop executes and b is first 0 and then 1. So you get [0,0] and [0,1]. When a is 1, the inner loop again executes and b is first 0 and then 1. So you get [1,0] and [1,1].
1st Jun 2020, 8:20 AM
Avinesh
Avinesh - avatar
+ 3
thats same as for a in range(0,2): for b in range(0,2): x.append([a,b]) it goes [0,0],[0,1],[1,0],[1,1]
1st Jun 2020, 8:21 AM
durian
durian - avatar
0
Avinesh Lily Mea thanks, this was very misleading.
1st Jun 2020, 8:28 AM
Tricker