![](/img/trans.png)
[英]Python regex: Match any text excluding 2 words (probably look arounds)
[英]Excluding words in Conditions in Python
我目前正在尝试编写一个有多个条件的程序。 我想从标记列表中排除单词列表(det)。 直到if len(W) <=8:
它的工作正如我想要的那样。 但是,我无法让该程序在我的令牌列表中找到det中的任何单词,并将其从打印中排除。
这是我目前拥有的:
det = ['the','a',an','\'s']
w for w in tkV if w not in det
def BT_pos1(w):
for w in tkV:
if w.islower():
if len(w) >=3:
if len(w) <=8:
if w not in det:
print w, ' may be a bt.'
您的det
似乎无效(请检查引号)。
如果要经常检查元素是否在列表中,可以使用set()
,它可以更快地检查内容。
整体看起来像这样:
det = set(["the", "a", "an", "'s"])
for w in tkV:
if 3 <= len(w) <= 8 and w not in det and w.islower():
print w, ' may be a bt.'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.