Skip to content

Instantly share code, notes, and snippets.

@squizduos
Created October 14, 2019 11:45
Show Gist options
  • Save squizduos/a9b6a8a00246fc6ac576658303656efc to your computer and use it in GitHub Desktop.
Save squizduos/a9b6a8a00246fc6ac576658303656efc to your computer and use it in GitHub Desktop.
Encode integer to short url-friendly string with Python 3
import string
def hex_encode_int(n):
alphabet = string.digits + string.ascii_uppercase + string.ascii_lowercase
result = ""
while n:
n, t = divmod(n, len(alphabet))
result += alphabet[t]
return result or "0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment