def wordSeg(str): english = 'abcdefghijklmnopqrstuvwxyz0123456789' output = [] buffer = '' #str=str.lower() for s in str: if s in english or s in english.upper(): #英文或数字 buffer += s else: #中文 if buffer: output.append(buffer) buffer = '' output.append(s) if buffer: output.append(buffer) return output str = '我叫Xiaoming,来自山东,今年2岁了,今天星期一,大家早上好,Good morning' print(wordSeg(str))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)