Incrementing letters

Wolfram Kraus kraus at hagen-partner.de
Fri May 27 08:12:37 EDT 2005


Heiko Wundram wrote:
> Am Freitag, 27. Mai 2005 13:31 schrieb Michael:
> 
>>if(C == 'z') C='a';
>>else C++;
> 
> 
> if C == "z":
>   C = "a"
> else:
>   C = chr(ord(C)+1)
> 
According to the OP's problem (with the assumption that only characters 
  from a-z are given) he might even try a lil LC:
 >>> s = "shiftthis"
 >>> ''.join([chr(((ord(x)-ord('a')+1)%26)+ord('a')) for x in s])
'tijguuijt'


HTH,
Wolfram



More information about the Python-list mailing list