Logo

Programming-Idioms

History of Idiom 26 > diff from v82 to v83

Edit summary for version 83 by Anon:
[Python] Use _ instead of i

Version 82

2021-08-16, 13:01:08

Version 83

2021-08-16, 13:02:00

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Variables
x,m,n
Variables
x,m,n
Extra Keywords
2d
Extra Keywords
2d
Code
x = [[0]*n for i in range(m)]
Code
x = [[0] * n for _ in range(m)]
Comments bubble
You can't use the multiplication idiom for the outer array, because, it would just duplicate the references to the inner arrays.
Comments bubble
You can't use the multiplication idiom for the outer array, because, it would just duplicate the references to the inner arrays.