def luhn(candidate):
 if (not isinstance(candidate, basestring)):
  candidate = str(candidate)
 try:
  evens = sum([int(c) for c in candidate[(-1)::(-2)]])
  odds = sum([LUHN_ODD_LOOKUP[int(c)] for c in candidate[(-2)::(-2)]])
  return (((evens + odds) % 10) == 0)
 except ValueError:
  return False

def luhn ( candidate ) : if ( not isinstance ( candidate , basestring ) ) : candidate = str ( candidate ) try : evens = sum ( [ int ( c ) for c in candidate [ ( - 1 ) : : ( - 2 ) ] ] ) odds = sum ( [ LUHN_ODD_LOOKUP [ int ( c ) ] for c in candidate [ ( - 2 ) : : ( - 2 ) ] ] ) return ( ( ( evens + odds ) % 10 ) == 0 ) except ValueError : return False
checks a candidate number for validity according to the luhn algorithm .