琴韵悠幽 2020-07-29 18:51 采纳率: 100%
浏览 328
已采纳

python中jieba分词怎么把字母一个一个单独分开。

在字典中加入了26个字母没有用
比如“hello你好”仍然会分成“hello 你好”
我想得到“h e l l o 你好”,请问怎么处理
同样还有shu'zi

  • 写回答

1条回答 默认 最新

  • jingluan666 2020-07-30 08:22
    关注
    import re
    
    sentence="hello你好"
    result=re.sub(r"([a-zA-Z])",r"\1 ", sentence)
    print(result.rstrip())
    

    或者:

    import re
    
    sentence="hello你好"
    result=""
    
    for chr in sentence:
        if(re.match(r"[a-zA-Z]", chr)):
            result+=chr+" "
        else:
            result+=chr
    
    print(result.rstrip())
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?