def bankcard_type(card_number):
 def matches(card_number, lengths, prefixes):
  if (len(card_number) not in lengths):
   return False
  for prefix in prefixes:
   if card_number.startswith(prefix):
    return True
  return False
 for (card_type, lengths, prefixes) in CARD_TYPES:
  if matches(card_number, lengths, prefixes):
   return card_type

def bankcard_type ( card_number ) : def matches ( card_number , lengths , prefixes ) : if ( len ( card_number ) not in lengths ) : return False for prefix in prefixes : if card_number . startswith ( prefix ) : return True return False for ( card_type , lengths , prefixes ) in CARD_TYPES : if matches ( card_number , lengths , prefixes ) : return card_type
return the type of a bankcard based on its card_number .