string.maketrans().lower()

  • Thread starter Hallvard B Furuseth
  • Start date
H

Hallvard B Furuseth

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)))?
 
E

Erik Max Francis

Hallvard said:
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.
BTW, is there a simpler way to write "".join(map(chr, xrange(256)))?

You could use a list comprehension if you prefer.
 
P

Peter Abel

Hallvard B Furuseth said:
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.

Regards
Peter
 
H

Hallvard B Furuseth

Erik said:
Sure. The return value of string.maketrans is just itself a string,
after all.
Thanks.


You could use a list comprehension if you prefer.

map() looks clearer to me in this case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,205
Messages
2,571,067
Members
47,673
Latest member
MahaliaPal

Latest Threads

Top