string.maketrans().lower()

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Thu Sep 2 13:26:40 EDT 2004


Erik Max Francis wrote:
>Hallvard B Furuseth wrote:
>> 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())
> 
> Sure.  The return value of string.maketrans is just itself a string,
> after all.

Thanks.

>> BTW, is there a simpler way to write "".join(map(chr, xrange(256)))?
> 
> You could use a list comprehension if you prefer.

map() looks clearer to me in this case.

-- 
Hallvard



More information about the Python-list mailing list