diff options
author | Antoine Beaupré <anarcat@debian.org> | 2018-03-14 12:24:17 -0400 |
---|---|---|
committer | Antoine Beaupré <anarcat@debian.org> | 2018-03-14 12:24:17 -0400 |
commit | 0a297829eaf3912c939e1b43a3ef6ddeb7607b38 (patch) | |
tree | 51733e0d6ffb00f0f7dfe01dccd48b2a598e5153 /raphodo/utilities.py | |
parent | 88c8bd4cd2ee4707f8a43be4d89c4e040dcced2f (diff) |
New upstream version 0.9.9upstream/0.9.9
Diffstat (limited to 'raphodo/utilities.py')
-rw-r--r-- | raphodo/utilities.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/raphodo/utilities.py b/raphodo/utilities.py index a70fb56..838709c 100644 --- a/raphodo/utilities.py +++ b/raphodo/utilities.py @@ -833,3 +833,36 @@ def arrow_locale() -> str: return lang except (ValueError, AttributeError): return default + + +def letters(x: int) -> str: + """ + Return a letter representation of a positive number. + + Adapted from algorithm at + http://en.wikipedia.org/wiki/Hexavigesimal + + >>> letters(0) + 'a' + >>> letters(1) + 'b' + >>> letters(2) + 'c' + >>> letters(25) + 'z' + >>> letters(26) + 'aa' + >>> letters(27) + 'ab' + >>> letters(28) + 'ac' + """ + + v = '' + while x > 25: + r = x % 26 + x = x // 26 - 1 + v = string.ascii_lowercase[r] + v + v = string.ascii_lowercase[x] + v + + return v |