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