python中的lambda表达式错误

时间:2017-06-02 16:50:34

标签: python list lambda nltk

我试图开发一个lambda表达式分类。以下是我的代码到目前为止,

import nltk
list2=nltk.word_tokenize("I win it")
list1 = ['gain', 'archive', 'win', 'success']

set1 = set(list1)
result = []
for item, nextitem in zip(list2, list2[1:]):
if item in set1:
    result.append(nextitem)
print result

new_result =nltk.pos_tag(result)
words, tags = zip(*new_result)

def classify(s, rls):
  for (f, emotion) in rls:
  if f(s):
     return emotion
 return "neutral"

rules = [(lambda x: x[result != []] & [['PRP' in(tags)]], "happy"),
     (lambda x: x[result != []] & [['PRP' not in(tags)]], "neutral"),]

 print classify("I successfully done my exam", rules)

但它会出现以下错误。

rules = [(lambda x: x[result != []] & [['PRP' in(tags)]], "happy"),
TypeError: unsupported operand type(s) for &: 'str' and 'list'

如何修复此错误。请帮帮我!

0 个答案:

没有答案