Incrementing letters
Rocco Moretti
roccomoretti at hotpop.com
Fri May 27 11:30:10 EDT 2005
Dan Sommers wrote:
> 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)
>
>
>>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.
>
Not quite:
>>> string.ascii_letters[ 1 : ] + string.ascii_letters[ 0 ]
'bcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZa'
i.e. you get 'z' -> 'A' and 'Z' -> 'a'
Another issue is locale settings and special characters - what should be
done with accented letters? Preserve letter, or shift and loose accent?
More information about the Python-list
mailing list