![](/img/trans.png)
[英]python to remove space between Chinese unicode strings but not between English words
[英]How to remove space between English Words after extracting from pdfplumber
我建议寻找两个不在您的语料库中的后续单词的出现,这应该揭示这种拆分不会导致其他英语单词的所有情况。
将带有两个空格的单词放入列表的示例逻辑,然后您可以实现您喜欢的功能:
text = """
asdasd asd asdd d
uuurr ii ii rrr
"""
words = text.split(" ") #<- split if 1 spaces
dictionary = list() #<- dictionary list to compare
words_wrapper = list() #<- list of words with 2 spaces
for idx in range(len(words)):
if words[idx] == '':
word = f"{words[idx-1]} {words[idx+1]}"
words_wrapper.append(word)
if word in dictionary:
pass #<- do sth
# Print filtered words
print(words_wrapper)
或者您也可以使用 .join 将带有 2 个空格的单词组合在一起:
text = """
asdasd asd asdd d
uuurr ii ii rrr
"""
print("".join(text.split(" ")))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.