Double loops inside list. | SoloLearn: Learn to code for FREE!

+2

Double loops inside list.

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

6/1/2020 8:13:19 AM

Tricker

3 Answers

New Answer

+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].

+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]

0

Avinesh Lily Mea thanks, this was very misleading.