How to do a Python split() on languages (like Chinese) that don't use whitespace as word separator?

后端 未结 9 2464
梦如初夏
梦如初夏 2020-12-03 03:25

I want to split a sentence into a list of words.

For English and European languages this is easy, just use split()

>>> \"This is a sentence.         


        
9条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 04:15

    if str longer than 30 then take 27 chars and add '...' at the end
    otherwise return str

    str='中文2018-2020年一区6、8、10、12号楼_「工程建设文档102332号」'
    result = len(list(str)) >= 30 and ''.join(list(str)[:27]) + '...' or str
    

提交回复
热议问题