将列表传递给函数、direct和indi

2024-04-29 13:51:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下功能:

def search_stmts(stmts,lower_bound_sura,lower_bound_aya,higher_bound_sura = -1,higher_bound_aya = -1):
     ayas_list = []
     cnt = 0
     for cnt in range(len(stmts[0])):
         if stmts[0][cnt] == "root":
             ayas_list.append(self.root_lookup(stmts[1][cnt], basicrecord_instance.get_ayas_with_addressing( \
                                lower_bound_sura,lower_bound_aya,higher_bound_sura, higher_bound_aya)))
         elif stmts[0][cnt] == "word":
             #print(stmts[1][cnt])
             ayas_list.append(self.word_lookup(stmts[1][cnt], basicrecord_instance.get_ayas_with_addressing( \
                                   lower_bound_sura,lower_bound_aya,higher_bound_sura, higher_bound_aya)))

     return self.search_ayas(ayas_list)

它将stmts作为嵌套列表:[['word','root','word'],['hello','how','are']]和4int参数。
当我将函数调用为:

search_stmts([['word','word','root'],['hello','how','are']],1,1)

以上通话正常

但是如果我有以下调用,它不会得到任何数据:

list1 = ['root','word','root']
list2 = ['hello','how','are']
search_stmts([list1,list2],1,1)   

我怎样才能把我的两张单子作为一张单子传递呢


Tags: selfhellosearchrootlowerlisthowword
1条回答
网友
1楼 · 发布于 2024-04-29 13:51:33

如果我去掉“basicrecord\u instance”和“self”的functions,就会得到准确的结果

def search_stmts(stmts,lower_bound_sura,lower_bound_aya,higher_bound_sura = -1,higher_bound_aya = -1):
     ayas_list = []
     cnt = 0
     print(range(len(stmts[0])))
     for cnt in range(len(stmts[0])):
         print(cnt)
         if stmts[0][cnt] == "root":
             ayas_list.append((stmts[1][cnt], lower_bound_sura,lower_bound_aya,higher_bound_sura, higher_bound_aya))
         elif stmts[0][cnt] == "word":
             #print(stmts[1][cnt])
             ayas_list.append((stmts[1][cnt],                                    lower_bound_sura,lower_bound_aya,higher_bound_sura, higher_bound_aya))
     return ayas_list

print(search_stmts([['word','word','root'],['hello','how','are']],1,1))
list1 = ['root','word','root']
list2 = ['hello','how','are']


print(search_stmts([list1,list2],1,1))

而我正在

[('hello', 1, 1, -1, -1), ('how', 1, 1, -1, -1), ('are', 1, 1, -1, -1)]
[('hello', 1, 1, -1, -1), ('how', 1, 1, -1, -1), ('are', 1, 1, -1, -1)]

相关问题 更多 >