Incrementing letters

Dan Sommers me at privacy.net
Fri May 27 10:52:36 EDT 2005


On Fri, 27 May 2005 16:10:32 +0200,
Wolfram Kraus <kraus at hagen-partner.de> wrote:

> Duncan Booth wrote:

>>>>> import string
>>>>> upone = string.maketrans(
>> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
>> 'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA')
>> 
>>>>> string.translate("I've got a string s....", upone)

>> "J'wf hpu b tusjoh t...."

>> Note the difference though: the Python code does what you said you
>> wanted, whereas your sample code corrupts punctuation.

> Wow, that's quite nice. You really learn something new every day :-) A
> minor improvement: Use string.ascii_letters as the first parameter for
> string.maketrans

And use string.ascii_letters[ 1 : ] + string.ascii_letters[ 0 ] for the
second parameter to string.maketrans.

Regards,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>



More information about the Python-list mailing list