string.maketrans().lower()

Peter Abel PeterAbel at gmx.net
Wed Sep 1 07:05:08 EDT 2004


Hallvard B Furuseth <h.b.furuseth at usit.uio.no> wrote in message news:<HBF.20040901ee1r at bombur.uio.no>...
> I have a translation table from
>   tr = string.maketrans(...)
> and want a table which produces the same characters lowercased.
> 
> `tr.lower()' works - at least with Python 2.3 - but is that will
> that remain reliable?  Or should I use something like this?
> 
>  string.maketrans("".join(map(chr, xrange(256))),
>                   "".join(map(chr, xrange(256))).translate(tr).lower())
> 
> BTW, is there a simpler way to write "".join(map(chr, xrange(256)))?

Not 256 chars, but some of them where lower and upper really makes sense.

>>> import string
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
>>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> 

Regards
Peter



More information about the Python-list mailing list