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