def get_characteristic_subpattern(subpatterns):
 if (not isinstance(subpatterns, list)):
  return subpatterns
 if (len(subpatterns) == 1):
  return subpatterns[0]
 subpatterns_with_names = []
 subpatterns_with_common_names = []
 common_names = ['in', 'for', 'if', 'not', 'None']
 subpatterns_with_common_chars = []
 common_chars = '[]().,:'
 for subpattern in subpatterns:
  if any(rec_test(subpattern, (lambda x: (type(x) is str)))):
   if any(rec_test(subpattern, (lambda x: (isinstance(x, str) and (x in common_chars))))):
    subpatterns_with_common_chars.append(subpattern)
   elif any(rec_test(subpattern, (lambda x: (isinstance(x, str) and (x in common_names))))):
    subpatterns_with_common_names.append(subpattern)
   else:
    subpatterns_with_names.append(subpattern)
 if subpatterns_with_names:
  subpatterns = subpatterns_with_names
 elif subpatterns_with_common_names:
  subpatterns = subpatterns_with_common_names
 elif subpatterns_with_common_chars:
  subpatterns = subpatterns_with_common_chars
 return max(subpatterns, key=len)

def get_characteristic_subpattern ( subpatterns ) : if ( not isinstance ( subpatterns , list ) ) : return subpatterns if ( len ( subpatterns ) == 1 ) : return subpatterns [ 0 ] subpatterns_with_names = [ ] subpatterns_with_common_names = [ ] common_names = [ 'in' , 'for' , 'if' , 'not' , 'None' ] subpatterns_with_common_chars = [ ] common_chars = '[]().,:' for subpattern in subpatterns : if any ( rec_test ( subpattern , ( lambda x : ( type ( x ) is str ) ) ) ) : if any ( rec_test ( subpattern , ( lambda x : ( isinstance ( x , str ) and ( x in common_chars ) ) ) ) ) : subpatterns_with_common_chars . append ( subpattern ) elif any ( rec_test ( subpattern , ( lambda x : ( isinstance ( x , str ) and ( x in common_names ) ) ) ) ) : subpatterns_with_common_names . append ( subpattern ) else : subpatterns_with_names . append ( subpattern ) if subpatterns_with_names : subpatterns = subpatterns_with_names elif subpatterns_with_common_names : subpatterns = subpatterns_with_common_names elif subpatterns_with_common_chars : subpatterns = subpatterns_with_common_chars return max ( subpatterns , key = len )
picks the most characteristic from a list of linear patterns current order used is: names > common_names > common_chars .