python 处理特殊的数字字符

2017-12-06  本文已影响0人  hapjin

处理特殊的数字

输出emoji字符

判断某字符串中是否包含数字(包括特殊数字)

def hasNumbers(chat):
    return any(char.isdigit() for char in chat)

汉字转换成拼音

使用pypinyin包

from pypinyin import pinyin
chat1 = "承认"
chatList = pinyin(chat1)
chatList
Out[56]: [['chéng'], ['rèn']]
words1 = [wordlist[0] for wordlist in chatList]
words1
Out[58]: ['chéng', 'rèn']
chat2 = "城认"
chatList2 = pinyin(chat2)
words2 = [wordlist[0] for wordlist in chatList2]
words2
Out[62]: ['chéng', 'rèn']
chat3 = "城朲"
chatList3 = pinyin(chat3)
chatList3
Out[65]: [['chéng'], ['rén']]
words3 = [wordlist[0] for wordlist in chatList3]
words3
Out[67]: ['chéng', 'rén']

特殊字符查询网站

Unicode Circled Numbers ① ② ③

1.png

Unicode 10.0 Character Code Charts

2.png
上一篇 下一篇

猜你喜欢

热点阅读