How can a character map normalize several known punctuation variants in one pass?
translate looks up code points in a translation table and can replace a character with a string or delete it with None.
Python example and interpretation
Map a fullwidth comma to ASCII and remove a zero-width space in this fixture. Decide removals per corpus because some scripts rely on formatting characters.
table=str.maketrans({',':',','\u200b':None})
'猫,\u200b狗'.translate(table)Result '猫,狗'
中文
怎样用字符映射一次处理一组固定的标点差异?
translate 按码点查映射表,可将字符替换成字符串或用 None 删除。
Python 算例与适用条件
将全角逗号改为半角并去掉零宽空格。是否删除不可见字符应服从语料规范,部分文字系统依赖格式字符。
table=str.maketrans({',':',','\u200b':None})
'猫,\u200b狗'.translate(table)结果 '猫,狗'