with open('text.txt','r') as f:
for i in f:
trantab = str.maketrans({key: None for key in string.punctuation})
j = i.translate(trantab)
result1.append(j)
shortword = re.compile(r'\W*\b\w{1,4}\b')
shortword.sub('', result1)
f = result1
错误是:
line 13, in shortword.sub('', result1)
TypeError: expected string or bytes-like object
我该怎么修?你知道吗
假设每个单词都在一行中,如果不是这样,就必须用
.split()
分解content
出现此错误是因为您正在尝试[].sub()数组。。。你知道吗
我用这个脚本解决了你需要的问题:
你只需要分配短词.sub('',result1)到result1并确保使用str():
我相信那会对你有好处的!你知道吗
相关问题 更多 >
编程相关推荐