我不确定是否还有其他相关问题。如果是,请告诉我。。。我已经找过了,但找不到。。你知道吗
我想数一数单词表,如果某些单词前面没有三个或更少的单词。。 下面是来自Count occurrences of a couple of specific words的示例
我想数单词,“foo”,“bar”,“baz”,除了“no”在单词前面三个或更少的单词。在这种情况下,一个吧台和一个foo不能计算。。你知道吗
vocab = ["foo", "bar", "baz"]
exception= ["no"]
s = "foo bar baz no bar quux foo bla bla"
wordcount = dict((x,0) for x in vocab)
for w in re.findall(r"\w+", s):
if w in wordcount:
wordcount[w] += 1
请帮帮我。。事先非常感谢。。你知道吗
只需用空字符串替换
no
和以下三个单词,然后计算结果字符串中的单词。你知道吗实际上,您可以使用Python的字符串来实现这一点,而不需要regex:
由于切片不会生成索引错误,因此可以将循环简化为:
关于:
这只是利用了一个事实,如果我们遇到“否”,我们可以跳过以下3个元素。你知道吗
相关问题 更多 >
编程相关推荐