if n == 0:
    break
return ''.join(reversed(s))

def num_decode(s):
    if s[0] == SIGN_CHARACTER:
        return -num_decode(s[1:])
n = 0
for c in s:
    n = n * BASE + ALPHABET_REVERSE[c]
return n
How to convert an integer to the shortest url-safe string in Python?