Python sample of short link decode

If anyone’s interested, the folks over at the Python forums have been extremely helpful and have provided an updated version of the shortlink decode routine that works:

def decodejs(sc):
    index_of = {x: y for y, x in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~")}
    x = y = 0
    z = -8
    i = 0
    for ch in sc:
        if (digit := index_of.get(ch)) is None:
            break
 
        # distribute 6 bits into x and y
        x <<= 3
        y <<= 3
        for j in range(2, -1, -1):
            if digit & 1 << (2 * j + 1):
                x |= 1 << j
            if digit & 1 << (2 * j):
                y |= 1 << j
        z += 3
        i += 1
 
    x = x * 2**(2 - 3 * i) * 90 - 180
    y = y * 2**(2 - 3 * i) * 45 - 90
 
    if i < len(sc) and sc[i] == "-":
        z -= 2
        if i + 1 < len(sc) and sc[i + 1] == "-":
            z += 1
 
    return z, y, x