Example 1: how to create 2d list in python
o=[]
for i in range(0,rows):
x=[]
for j in range(0,cols):
x.append(0)
o.append(x)
Example 2: 2d array python
array = [[value] * lenght] * height
//example
array = [[0] * 5] * 10
print(array)
Example 3: create a 2d array in python
def build_matrix(rows, cols):
matrix = []
for r in range(0, rows):
matrix.append([0 for c in range(0, cols)])
return matrix
if __name__ == '__main__':
build_matrix(6, 10)
Example 4: 2d array pytho
arr = [
[11, 12, 5],
[15, 6, 10],
[10, 8, 12],
[12, 15, 8]
]
Example 5: 2d array python3
matrix = [[False for col in range(6)] for row in range(5)]
matrix = [['banana' for col in range(5)] for row in range(6)]
Example 6: 2D array python
array_2d = [['row0, column0'], ['row0, column1'], ['row0, column2'],
['row1, column0'], ['row1, column1'], ['row1, column2'],
['row2, column0'], ['row2, column1'], ['row2, column2']]