Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 理解列表中循环的双变量嵌套_Loops_Nested_List Comprehension_Nested Loops - Fatal编程技术网

Loops 理解列表中循环的双变量嵌套

Loops 理解列表中循环的双变量嵌套,loops,nested,list-comprehension,nested-loops,Loops,Nested,List Comprehension,Nested Loops,我试图通过实现理解列表来改进代码 我有以下声明 test = [expression.match(self.sourceModel().index(source_row, column, source_parent).data()) for expression in liste for liste, column in self._filters.items()] 测试是字符串之间的正则表达式匹配,这些字符串来自表达式列表、包含在dict中的列表(列作为键)和

我试图通过实现理解列表来改进代码

我有以下声明

test = [expression.match(self.sourceModel().index(source_row, column, source_parent).data())
                for expression in liste for liste, column in self._filters.items()]
测试是字符串之间的正则表达式匹配,这些字符串来自表达式列表、包含在dict中的列表(列作为键)和表达式列表作为值

我不明白为什么我的变量“liste”被标记为未引用,因为它在最后一个for循环中被提到,有什么想法吗?

代码

test = [expression.match(self.sourceModel().index(source_row, column, source_parent).data()) for expression in liste for liste, column in self._filters.items() for expression in liste ]
解释

您的
liste
变量未被引用,因为您在循环中引用了liste变量,该循环仅在使用变量本身之后执行

请记住,将理解列为一个反向结构是正确的,b在
定义之前,然后是
循环
定义,但在每个部分中,逻辑顺序与正常循环代码相同