the next higher character - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: the next higher character (/thread-16829.html) Pages:
1
2
|
the next higher character - Skaperen - Mar-16-2019 i have a character as a string of length 1. i want the next higher character. 'a'->'b' or '4'->'5' or '9'->':'. i could do chr(ord(ch)+1). does python have any more elegant way? RE: the next higher character - heiner55 - Jun-06-2019 #!/usr/bin/python3 import string for ch in string.ascii_letters: print(ch) RE: the next higher character - Skaperen - Jun-06-2019 what character does that code yield? RE: the next higher character - heiner55 - Jun-07-2019 See: https://docs.python.org/3.7/library/string.html RE: the next higher character - Gribouillis - Jun-07-2019 You can use a bytearray of length 1, which is a writable array containing a single integer in the range [0, 256). You can use the latin-1 encoding to convert such an array to / from a str instance of length 1 (this is the same as the utf8 encoding for ords below 128). >>> t = bytearray('a', encoding='latin-1') >>> t bytearray(b'a') >>> t[0] += 5 >>> t bytearray(b'f') >>> t.decode('latin-1') 'f' RE: the next higher character - heiner55 - Jun-07-2019 Great. RE: the next higher character - Skaperen - Jun-07-2019 (Jun-07-2019, 02:33 AM)heiner55 Wrote: See: i think you didn't understand my question. i do not see an answer in that link. RE: the next higher character - heiner55 - Jun-07-2019 Because your question are always very complex. RE: the next higher character - Skaperen - Jun-07-2019 if the question is too hard to understand why post any answer at all? RE: the next higher character - heiner55 - Jun-07-2019 I did not think my answer was so bad. #!/usr/bin/python3 import string for ch in string.ascii_letters: print(ch) |