remove one unicode range from a unicode textfile in Python3
I have a Unicode textfile consisting of ranges q to r and s to t. I want to remove range s to t (which is in Chinese开发者_开发百科) leaving q to r (which is in English).
How can I do that in Python3?
Use the string translate method. To quote from the 3.1.3 Std Lib doc:
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.
精彩评论