0
我有一个由范围q到r和s到t组成的Unicode文本文件。我想删除范围s到t(这是中文),留下q到r(这是英文)。从Python3的unicode文本文件中删除一个unicode范围
我如何在Python3中做到这一点?
我有一个由范围q到r和s到t组成的Unicode文本文件。我想删除范围s到t(这是中文),留下q到r(这是英文)。从Python3的unicode文本文件中删除一个unicode范围
我如何在Python3中做到这一点?
使用字符串翻译方法。引用3.1.3 Std Lib文档:
str.translate(map)
Return a copy of the s where all characters have been mapped through the map
which must be a dictionary of Unicode ordinals (integers) to Unicode ordinals,
strings or None. Unmapped characters are left untouched. Characters mapped to
None are deleted.
You can use str.maketrans() to create a translation map from
character-to-character mappings in different formats.
在这种情况下什么是“范围”? “范围q到r”并不代表什么,因为q不是一个范围,而是一个字母。 :) – 2011-02-03 08:12:57