Sep 22, 2020

[Python] how to create a list (array) with a particular quantities of rows and columns

x = 5   # the number of columns

y = 10   # the number of rows

my_list = [[0 for col in range(x)] for row in range(y)] 

print (my_list)


result --------------------------------------------------------------------------------

[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]



No comments:

Post a Comment