If I am having
char = 'a'
how can I increase the value into 'b' and then into 'c' and so on..
I don't want to replace it or change it. Its much like
char = char + 1
>>> chr(ord('a') + 1)
'b'
You can make an incrementer translation like this. I've mapped 'z' back onto 'a' in this case
>>> from string import maketrans, ascii_lowercase
>>> char_incrementer = maketrans(ascii_lowercase, ascii_lowercase[1:]+ascii_lowercase[0])
>>> 'a'.translate(char_incrementer)
'b'
you can just as easily apply it to a whole string
>>> 'hello'.translate(char_incrementer)
'ifmmp'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With