Translation table to map Latin-1 to ASCII?

"Martin v. Löwis" martin at
Sun Jan 26 15:11:06 CET 2003

Rene Pijlman wrote:
> Sure, and I can also write it myself or get it from ht://Dig's
> source code. But I'm lazy and I was just hoping that someone
> would have a similar translation table for Python's
> string.translate lying around :-)

I feel that it takes more time to post a message to usenet than to 
actually write down the translation table. First, generate a string of 
all non-ASCII characters:

l = []
for i in range(160,256): l.append(chr(i))
print ''.join(l)

Then, edit it to contain only letters, in a text editor.
Finally, write a second line in the text editor, putting the unaccented 
character below the accented one, and you are done.

We are talking about sixty characters, total.

> I found the following solution in this group's archive on
> Google. If only I would understand how it works :-)

I suggest this is overkill. It uses the Unicode decomposition, dropping 
all combining characters from the decompositions. The test for "0" 
checks whether this is a canonical decomposition; compatibility 
decompositions start with "<".


More information about the Python-list mailing list