How to do calculations on alphabet in Python
The aim of this pageđ is to share how a simple pattern of âprogramming alphabetâ combining ord()
, chr()
and doing some math in between
Feb 28, 2023
for example, given a letter, return another letter that is in the middle between âaâ and the given letter
- Example: if the input is
c
, I want to receive theb
def mid_letter(letter):
return chr((ord(letter) - ord('a')) // 2 + ord('a'))
>>> >>> mid_letter("l")
'f'