def get_search_scores(query, choices, ignore_case=True, template='{}', valid_only=False, sort=False):
 query = query.replace(' ', '')
 pattern = get_search_regex(query, ignore_case)
 results = []
 for choice in choices:
  r = re.search(pattern, choice)
  if (query and r):
   result = get_search_score(query, choice, ignore_case=ignore_case, apply_regex=False, template=template)
  elif query:
   result = (choice, choice, NOT_FOUND_SCORE)
  else:
   result = (choice, choice, NO_SCORE)
  if valid_only:
   if (result[(-1)] != NOT_FOUND_SCORE):
    results.append(result)
  else:
   results.append(result)
 if sort:
  results = sorted(results, key=(lambda row: row[(-1)]))
 return results

def get_search_scores ( query , choices , ignore_case = True , template = '{}' , valid_only = False , sort = False ) : query = query . replace ( ' ' , '' ) pattern = get_search_regex ( query , ignore_case ) results = [ ] for choice in choices : r = re . search ( pattern , choice ) if ( query and r ) : result = get_search_score ( query , choice , ignore_case = ignore_case , apply_regex = False , template = template ) elif query : result = ( choice , choice , NOT_FOUND_SCORE ) else : result = ( choice , choice , NO_SCORE ) if valid_only : if ( result [ ( - 1 ) ] != NOT_FOUND_SCORE ) : results . append ( result ) else : results . append ( result ) if sort : results = sorted ( results , key = ( lambda row : row [ ( - 1 ) ] ) ) return results
search for query inside choices and return a list of tuples .