(\(\d+\))(.*?)
现在,重要的一点是:有没有办法轻松访问动态调用的数组的索引,例如class A(object):
def setup(self):
self.array1 = [1,2,3]
self.array2 = [4,5,6]
self.array3 = [7,8,9]
def function(self):
for i in range(1,4):
for j in range(3):
#code goes here
#code goes here
,并且能够轻松存储它/将其作为参数传递给一行功能?我知道可以使用arrayi[j]
将数组存储到临时变量中,然后从中访问列表索引,但有更简单的方法吗?
答案 0 :(得分:2)
也许你应该尝试使用列表清单?像这样:
class A(object):
def setup(self):
self.array = [
[1,2,3],
[4,5,6],
[7,8,9]
]
def function(self):
for i in range(3):
for j in range(3):
# self.array[i][j]
答案 1 :(得分:1)
更多Pythonic方式:
class A(object):
def setup(self):
self.array = [
[1,2,3],
[4,5,6],
[7,8,9]
]
def func(self):
for subl in self.array:
for num in subl:
# code here