>>> s ='pýtĥöñ\fis\tawesome\r\n'>>> remap ={...ord('\t'):'',...ord('\f'):'',...ord('\r'):None# Deleted...}>>> a = s.translate(remap)>>> a'pýtĥöñ is awesome\n'
你可以以这个表格为基础进一步构建更大的表格。比如,让我们删除所有的和音符:
>>>import unicodedata>>>import sys>>> cmb_chrs =dict.fromkeys(c for c in range(sys.maxunicode)...if unicodedata.combining(chr(c)))...>>> b = unicodedata.normalize('NFD', a)>>> b'pýtĥöñ is awesome\n'>>> b.translate(cmb_chrs)'python is awesome\n'