def baseN(num, b, numerals='0123456789abcdefghijklmnopqrstuvwxyz'):
    return num == 0 and numerals[0] or baseN(num // b, b, numerals).lstrip(
        numerals[0]) + numerals[num % b]
How to convert an integer in any base to a string?