def a2idx(j, n=None):
 if (type(j) is not int):
  try:
   j = j.__index__()
  except AttributeError:
   raise IndexError(('Invalid index a[%r]' % (j,)))
 if (n is not None):
  if (j < 0):
   j += n
  if (not ((j >= 0) and (j < n))):
   raise IndexError(('Index out of range: a[%s]' % (j,)))
 return int(j)

def a2idx ( j , n = None ) : if ( type ( j ) is not int ) : try : j = j . __index__ ( ) except AttributeError : raise IndexError ( ( 'Invalid index a[%r]' % ( j , ) ) ) if ( n is not None ) : if ( j < 0 ) : j += n if ( not ( ( j >= 0 ) and ( j < n ) ) ) : raise IndexError ( ( 'Index out of range: a[%s]' % ( j , ) ) ) return int ( j )
return integer after making positive and validating against n .