Advertisement
Sax

Second Search - PyZap

Sax
Apr 11th, 2013
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. def second_search(first_search_words, search_terms):
  2.     """Recibe el diccionario en ram con las first_search_words para
  3.    refinar la busqueda.
  4.  
  5.    Primero se eliminan los resultados que tengan menos coincidencias que
  6.    numero de caracteres. Posteriormente, cada palabra es separada en
  7.    caracteres, y se comparan uno a uno con las letras escogidas en el run.
  8.  
  9.    Regresa una lista de palabras.
  10.  
  11.    """
  12.  
  13.     flagged_for_deletion = []
  14.  
  15.     for word in first_search_words:
  16.         if first_search_words.get(word)[0] < first_search_words.get(word)[1]:
  17.             flagged_for_deletion.append(word)
  18.  
  19.     for word in flagged_for_deletion:
  20.         del first_search_words[word]
  21.  
  22.     used_chars = []
  23.     final_words = []
  24.     keys = first_search_words.keys()
  25.  
  26.     for word in keys:
  27.  
  28.         available = list(search_terms)
  29.         used_chars[:] = []
  30.         actual_word = list(word)
  31.  
  32.         for current_char in actual_word:
  33.             if current_char in available:
  34.                 used_chars.append(current_char)
  35.                 available.remove(current_char)
  36.  
  37.         sorted(actual_word)
  38.         sorted(used_chars)
  39.         available[:] = []
  40.  
  41.         if actual_word == used_chars:
  42.             final_words.append(word)
  43.  
  44.     return final_words
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement