Python如何克服TypeError:'bool'对象不可迭代

时间:2016-12-15 17:56:03

标签: python python-3.x if-statement

我的问题是我需要在ifany()语句中有两个条件,这两个条件是检查列表中的单词是否出现在一行中以及来自辅助列表的另一个单词是否也出现在同一行中。如果是,则打印出来。我已经使用了这个,如果在之前的函数中只检查一个,所以我不需要使用And运算符,我已经尝试读取替代品,但其他运算符不允许我达到我的条件。

cleanLex中的lword(cleanLex是在readfiles.py中创建并填充的列表)

以下是显示功能

的部分代码

Main.py:

from collections import Counter
from Categories.GainingAccess import GA
from Readfiles import *

# Speech Act Categories
CategoryGA = GA
# ----------------------

# Word hit counters
CategoryHits = []
LexiconHits = []
# ----------------------

# unsure if used at this point
cleansedLex = []
# ----------------------

# Lists to hold lines where words have been matched
matchedCatlines = []
matchedLexlines = []
TestLine = []


def languagemodel():
    for line in cleanChat.values():
        for lword in [cleanLex]:
            for cword in [CategoryGA]:
                for section in line:
                    if any(lword and cword in section for lword in
                           cleanLex and cword in CategoryGA):  # searches each section to find words matching words stored in cleanLex
                print("matched words %s and %s", "on line:    %s",
                      (lword, cword, section))


languagemodel()

追踪错误:

Traceback (most recent call last):
  File "C:/Users/Lewis Collins/Downloads/test/main.py", line 100, in <module>
    languagemodel()
  File "C:/Users/Lewis Collins/Downloads/test/main.py", line 89, in languagemodel
    cleanLex and cword in CategoryGA):  # searches each section to find words matching words stored in cleanLex
TypeError: 'bool' object is not iterable

有关如何解决或解决此问题的任何建议。

0 个答案:

没有答案