May-02-2019, 11:04 PM
I'm trying to figure out how to declare a 2d array (rows & columns); where the rows are dynamic
What I've been able to do is define number of rows, and columns are dynamic; which is the opposite of what I'm wanting...
I am looking for a way to have dynamic rows, with set columns...
row1 [value-a, value-b, value-c]
row2 [value-a, value-b, value-c]
.
.
rowX [value-a, value-b, value-c]
but the below code seems to make it 46 rows, columns dynamic (when I set range to 5, I get 5 rows, not 5 columns)
Thoughts on how to make the "rows" variable/dynamic?
PappaBear
What I've been able to do is define number of rows, and columns are dynamic; which is the opposite of what I'm wanting...
I am looking for a way to have dynamic rows, with set columns...
row1 [value-a, value-b, value-c]
row2 [value-a, value-b, value-c]
.
.
rowX [value-a, value-b, value-c]
but the below code seems to make it 46 rows, columns dynamic (when I set range to 5, I get 5 rows, not 5 columns)
Thoughts on how to make the "rows" variable/dynamic?
import time import os import collections howmany=6 rulenumber=0 my_2d_list =[[] for i in range(46)] for counter1 in range(howmany): ## number of fw policies for counter2 in (range(howmany)): rulenumber +=1 print (rulenumber) if (rulenumber % 2 == 0): if (rulenumber % 3 == 0): my_2d_list[rulenumber]=['even','div by 2','div by 3'] else: my_2d_list[rulenumber]=['even','div by 2','not by 3'] else: if (rulenumber % 3 == 0): my_2d_list[rulenumber]=['odd','not by 2','div by 3'] else: my_2d_list[rulenumber]=['odd','not by 2','not by 3'] print ("Security policy 1") print ("Print Row 1") print (my_2d_list[1]) print ("-----------------") print (" ") print ("Print Row 19") print (my_2d_list[19]) print ("-----------------") print (" ") print ("Print Row 36") print (my_2d_list[36])
Output:Print Row 1
['odd', 'not by 2', 'not by 3', 'extra', 'extra']
-----------------
Print Row 19
['odd', 'not by 2', 'not by 3', 'extra', 'extra']
-----------------
Print Row 36
['even', 'div by 2', 'div by 3']
Many thanks,PappaBear