我正在尝试使用 Python 和 NLTK,但似乎无法对它们使用正则表达式,并且无法找出原因。
>>> import nltk
>>> import re
>>> words = nltk.corpus.words.words('en')
>>> ed-words = [w for w in words if re.search('ed$', w)]
SyntaxError: can't assign to operator
最佳答案
正如其他人提到的,在变量名中使用 -
在大多数编程语言中几乎是非法的。
在Python中,您可以使用下划线:
ed_words = [w for w in words if re.search('ed$', w)]
关于Python正则表达式错误: "Can' t assign to operator",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19752632/