3/07/2019

python 2d array and rows and cols

#make array
W = 2
H = 3


list2d = []
for i in range(0,H):
w_list =[]
for j in range (0,W):
w_list.append((i,j))
list2d.append(w_list)


#print 2d array
print(list2d)


#get row and col
Height = Rows = len(list2d)
Width = Cols = len(list2d[0])


#check values
print( Rows, Cols)
print( Height, Width)

#print all elements
for i in range(0,Rows):
for j in range (0,Cols):
print(list2d[i][j])


output
[[(0, 0), (0, 1)], [(1, 0), (1, 1)], [(2, 0), (2, 1)]]
3 2
3 2
(0, 0)
(0, 1)
(1, 0)
(1, 1)
(2, 0)
(2, 1)

No comments:

Post a Comment