双变量嵌套理解列表中的循环
double variable nest for loop in comprehension list
我正在尝试通过实施理解列表来改进我的代码。
我有以下声明。
test = [expression.match(self.sourceModel().index(source_row, column, source_parent).data())
for expression in liste for liste, column in self._filters.items()]
测试是字符串之间的正则表达式匹配,来自表达式列表,包含在字典中的列表,将列作为键,将表达式列表作为值
我不明白为什么我的变量“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 变量,该循环仅在您使用变量本身后才执行!!
记住,认为列表理解是一个颠倒的结构是正确的,先是 item
定义,然后是 loop
定义,但在每个部分中,逻辑顺序与正常顺序相同循环代码
我正在尝试通过实施理解列表来改进我的代码。
我有以下声明。
test = [expression.match(self.sourceModel().index(source_row, column, source_parent).data())
for expression in liste for liste, column in self._filters.items()]
测试是字符串之间的正则表达式匹配,来自表达式列表,包含在字典中的列表,将列作为键,将表达式列表作为值
我不明白为什么我的变量“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 变量,该循环仅在您使用变量本身后才执行!!
记住,认为列表理解是一个颠倒的结构是正确的,先是 item
定义,然后是 loop
定义,但在每个部分中,逻辑顺序与正常顺序相同循环代码