def luhn(candidate):
if not isinstance(candidate, six.string_types):<EOL><INDENT>candidate = str(candidate)<EOL><DEDENT>try:<EOL><INDENT>evens = sum(int(c) for c in candidate[-<NUM_LIT:1>::-<NUM_LIT:2>])<EOL>odds = sum(LUHN_ODD_LOOKUP[int(c)] for c in candidate[-<NUM_LIT:2>::-<NUM_LIT:2>])<EOL>return ((evens + odds) % <NUM_LIT:10> == <NUM_LIT:0>)<EOL><DEDENT>except ValueError:  <EOL><INDENT>return False<EOL><DEDENT>
Checks a candidate number for validity according to the Luhn
algorithm (used in validation of, for example, credit cards).
Both numeric and string candidates are accepted.