+ 2

how the code works ?

n = 2 a = [[0] * n for i in range(n)] Output is --> [[0,0] , [0,0]] Please explain the output how it has come ?

23rd Sep 2018, 11:57 AM
đŸŒ·â“â“€đ”č𝓝ⓐ â“€â“—đ”žâ“đŸŒ·
đŸŒ·â“â“€đ”č𝓝ⓐ â“€â“—đ”žâ“đŸŒ· - avatar
1 RĂ©ponse
+ 1
a = [[0]*2 for i in range(2)] [0]*2 = [0]+[0] = [0,0] range(2) contains 2 numbers so [0,0] is used twice. result is a list containing [0,0] twice.
23rd Sep 2018, 12:07 PM
davy hermans
davy hermans - avatar