Skip to content

Instantly share code, notes, and snippets.

@ki-chi
Created January 24, 2017 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ki-chi/fe8bf8d364d37561a8795eaca778d9bd to your computer and use it in GitHub Desktop.
Save ki-chi/fe8bf8d364d37561a8795eaca778d9bd to your computer and use it in GitHub Desktop.
The function for converting tricky-format digits
## Convert strings of 2-digits number have the following tricky format to an integer.
## Tricky format: the last digit is described as decimal, and the first digit is chosen from {1, ..., 9, A, ..., Z, a, ..., z}.
## The min is 0(="00") and the max is 619(="z9").
## Example: "15" -> 15, "A0" -> 100, "Z9" -> 359, "a0" -> 360, "c5" -> 385
def num2int(num):
if num.isdigit():
return int(num)
elif num[0].isupper():
return int(num[0], 36) * 10 + int(num[1])
else:
return int(num[0], 36) * 10 + 260 + int(num[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment