1array = [[value] * lenght] * height
2
3//example
4array = [[0] * 5] * 10
5
6print(array)
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# 5x6, 2-d array of booleans using list comprehension:
2
3matrix = [[False for col in range(6)] for row in range(5)]
4
5# 6x5, 2-d array of banana's using list comprehension:
6
7matrix = [['banana' for col in range(5)] for row in range(6)]