Skip to content

Instantly share code, notes, and snippets.

@tsangwpx
Created February 12, 2021 10:10
Show Gist options
  • Save tsangwpx/b66e0a3a95cbf8992f18c99eb016a873 to your computer and use it in GitHub Desktop.
Save tsangwpx/b66e0a3a95cbf8992f18c99eb016a873 to your computer and use it in GitHub Desktop.
def alphaonly_ordinal(n):
"""
Use alphabets as ordinal symbols
a = 1, b = 2, ..., z = 26,
aa = 27, ab = 28, etc
"""
assert n > 0
s = ''
while n:
n -= 1 # 1-based to 0-based indexing
n, r = divmod(n, 26)
s += chr(97 + r)
return s[::-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment