#NEWLINE# def digits( n , b = 10 ) : #NEWLINE# #INDENT# '\n    Return a list of the digits of n in base b. The first element in the list\n    is b (or -b if n is negative).\n\n    Examples\n    ========\n\n    >>> from sympy.ntheory.factor_ import digits\n    >>> digits(35)\n    [10, 3, 5]\n    >>> digits(27, 2)\n    [2, 1, 1, 0, 1, 1]\n    >>> digits(65536, 256)\n    [256, 1, 0, 0]\n    >>> digits(-3958, 27)\n    [-27, 5, 11, 16]\n    ' #NEWLINE# b = as_int ( b ) #NEWLINE# n = as_int ( n ) #NEWLINE# if ( b <= 1 ) : #NEWLINE# #INDENT# raise ValueError ( 'b must be >= 2' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( x , y ) = ( abs ( n ) , [ ] ) #NEWLINE# while ( x >= b ) : #NEWLINE# #INDENT# ( x , r ) = divmod ( x , b ) #NEWLINE# y . append ( r ) #NEWLINE# #UNINDENT# y . append ( x ) #NEWLINE# y . append ( ( ( - b ) if ( n < 0 ) else b ) ) #NEWLINE# y . reverse ( ) #NEWLINE# return y