1array = [[value] * lenght] * height
2
3//example
4array = [[0] * 5] * 10
5
6print(array)
1from array import *
2
3T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
4for r in T:
5 for c in r:
6 print(c,end = " ")
7 print()
1def build_matrix(rows, cols):
2 matrix = []
3
4 for r in range(0, rows):
5 matrix.append([0 for c in range(0, cols)])
6
7 return matrix
8
9if __name__ == '__main__':
10 build_matrix(6, 10)
1# Creates a list containing 5 lists, each of 8 items, all set to 0
2w, h = 8, 5;
3Matrix = [[0 for y in range(h)] for x in range(w)]
4
5Matrix[0][0] = 1
6Matrix[0][6] = 3 # error! range...
7Matrix[6][0] = 3 # valid
8
1array = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
2
3print(array[0])
4
5print(array[1][2])