url_shortener/baseconv.py
def _convert(number, fromdigits, todigits):
        """
        Converts a "number" between two bases of arbitrary digits.

        The input number is assumed to be a string of digits from the
        'fromdigits' string (which is in order of smallest to largest digit).
        The return value is a string of elements from 'todigits'
        (ordered in the same way). The input and output bases are
        determined from the lengths of the digit strings. Negative
        signs are passed through.

        Based on: http://code.activestate.com/recipes/111286/
        """

        if str(number)[0] == '-':
            number, neg = str(number)[1:], 1
        else:
            neg = 0

        # Make an integer out of the number
        x = 0

        for digit in str(number):
            x = x * len(fromdigits) + fromdigits.index(digit)

        # Create the result in base 'len(todigits)'
        if x == 0:
            res = todigits[0]
        else:
            res = ''

            while x > 0:
                x, digit = divmod(x, len(todigits))
                res = todigits[digit] + res

            if neg:
                res = '-' + res

        return res

        Converts a "number" between two bases of arbitrary digits.

        The input number is assumed to be a string of digits from the
        'fromdigits' string (which is in order of smallest to largest digit).
        The return value is a string of elements from 'todigits'
        (ordered in the same way). The input and output bases are
        determined from the lengths of the digit strings. Negative
        signs are passed through.

        Based on: http://code.activestate.com/recipes/111286/
        
Converts a "number" between two bases of arbitrary digits.
The input number is assumed to be a string of digits from the
'fromdigits' string (which is in order of smallest to largest digit).
The return value is a string of elements from 'todigits'
(ordered in the same way). The input and output bases are
determined from the lengths of the digit strings. Negative
signs are passed through.


Converts a " number " between two bases of arbitrary digits . The input number is assumed to be a string of digits from the ' fromdigits ' string ( which is in order of smallest to largest digit ) . The return value is a string of elements from ' todigits ' ( ordered in the same way ) . The input and output bases are determined from the lengths of the digit strings . Negative signs are passed through .
def _convert(number, fromdigits, todigits):
        if str(number)[0] == '-':
            number, neg = str(number)[1:], 1
        else:
            neg = 0
        x = 0
        for digit in str(number):
            x = x * len(fromdigits) + fromdigits.index(digit)
        if x == 0:
            res = todigits[0]
        else:
            res = ''
            while x > 0:
                x, digit = divmod(x, len(todigits))
                res = todigits[digit] + res
            if neg:
                res = '-' + res
        return res
def _convert ( number , fromdigits , todigits ) : if str ( number ) [ 0 ] == '-' : number , neg = str ( number ) [ 1 : ] , 1 else : neg = 0 x = 0 for digit in str ( number ) : x = x * len ( fromdigits ) + fromdigits . index ( digit ) if x == 0 : res = todigits [ 0 ] else : res = '' while x > 0 : x , digit = divmod ( x , len ( todigits ) ) res = todigits [ digit ] + res if neg : res = '-' + res return res
Converts a "number" between two bases of arbitrary digits.
Converts a " number " between two bases of arbitrary digits .
"""
        Converts a "number" between two bases of arbitrary digits.

        The input number is assumed to be a string of digits from the
        'fromdigits' string (which is in order of smallest to largest digit).
        The return value is a string of elements from 'todigits'
        (ordered in the same way). The input and output bases are
        determined from the lengths of the digit strings. Negative
        signs are passed through.

        Based on: http://code.activestate.com/recipes/111286/
        """ # Make an integer out of the number # Create the result in base 'len(todigits)'
number
fromdigits
todigits