我想通过查询100000(或仅查询100,000)来搜索100,000和100000.
有可能像那样搜索.
执行此操作的目的是,用户可以在任何地方添加逗号或根本不添加逗号,但无论如何都应搜索字符串(100,000或100000)...
我尝试在 python 中使用 string.punctuation 函数。我在 python 3.5 版本中这样做。这是我的以下代码:
import string
def check(text):
x=set(text.punctuation())
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
'str' object has no attribute 'punctuation'
Run Code Online (Sandbox Code Playgroud)
请帮助正确使用 this 的方法。我什至尝试使用 ispunct() 功能。
我尝试解决这个问题,如下面的链接所示,但无法弄清楚。
假设我有一个"10,5,3"字符串如何摆脱逗号,所以字符串只是"10 5 3"?我应该使用strtok吗?
我无法弄清楚为什么这不起作用:
import nltk
from nltk.corpus import stopwords
import string
with open('moby.txt', 'r') as f:
moby_raw = f.read()
stop = set(stopwords.words('english'))
moby_tokens = nltk.word_tokenize(moby_raw)
text_no_stop_words_punct = [t for t in moby_tokens if t not in stop or t not in string.punctuation]
print(text_no_stop_words_punct)
Run Code Online (Sandbox Code Playgroud)
看着输出我有这个:
[...';', 'surging', 'from', 'side', 'to', 'side', ';', 'spasmodically', 'dilating', 'and', 'contracting',...]
Run Code Online (Sandbox Code Playgroud)
似乎标点符号仍在那里.我做错了什么?