您正在寻找
[1 if any(word in i for word in top_words_list) else 0 for i in amazon['reviewer_summary']]
re.search()
返回a
list
在所有的比赛中。所以,当你这样做的时候
if re.search() in i
,您正在检查
if <list> in <string>
这就是为什么
TypeError
。
同样的一个小演示:
>>> chars_to_check = ['a', 'b', 'c']
>>> sentence = 'this is a sentence'
>>> chars_to_check in sentence
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'in <string>' requires string as left operand, not list
>>>
>>> any(c in sentence for c in chars_to_check)
True