473,395 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

string.maketrans().lower()

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

--
Hallvard
Jul 18 '05 #1
3 3766
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.
BTW, is there a simpler way to write "".join(map(chr, xrange(256)))?


You could use a list comprehension if you prefer.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ Procrastination is the thief of time.
-- Edward Young
Jul 18 '05 #2
Hallvard B Furuseth <h.**********@usit.uio.no> wrote in message news:<HB**************@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
Jul 18 '05 #3
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
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Behrang Dadsetan | last post by:
Hi all, I would like deleting specific characters from a string. As an example, I would like to delete all of the '@' '&' in the string 'You are ben@orange?enter&your&code' so that it becomes...
2
by: John F Dutcher | last post by:
There must be a 'fundamental' reason why 'string' functions are reported as 'not found' even though the 'import string' statement is present. If the script has user-defined functions at its...
3
by: steve morin | last post by:
http://www.python.org/doc/2.4.1/lib/node110.html These methods are being deprecated. What are they being replaced with? Does anyone know? Steve
10
by: John Salerno | last post by:
Can someone tell me what's happening here. This is my code: PUNCT_SPACE_SET = set(string.punctuation + string.whitespace) def filter_letters(original): return ''.join(set(original) -...
1
by: peterbe | last post by:
This has always worked fine for me. Peter fine Now if I do it with a unicode string: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/string.py", line...
22
by: hg | last post by:
Hi, I'm bringing over a thread that's going on on f.c.l.python. The point was to get rid of french accents from words. We noticed that len('à') != len('a') and I found the hack below to fix...
4
by: Terry Reedy | last post by:
Cédric Lucantis wrote: 'ae' I do not claim this to be better than all the other methods, but this pair can also translate while deleting, which others cannot.
3
by: cirfu | last post by:
im doing the python challenge and well, i solved this problem with ruby :) phrase = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb...
15
by: ssecorp | last post by:
if i want to make a string downcase, is upper().swapcase() the onyl choice? there is no downer() ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.