Advertisement
Techybear

Vikka EXO1

Apr 1st, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. # https://github.com/Vikka/python_test_ground/blob/master/exo_lou/anagrammes.md
  2.  
  3. from unidecode import unidecode
  4. from re import split
  5.  
  6.  
  7. text = "A Tanger, le gérant, sans argent, ne put acheter de grenat. Le maire" \
  8.        " et Marie, à l'aube, lui en donnèrent un beau."
  9.  
  10.  
  11. def anagrams(text_):
  12.     final = list()
  13.     list_words = split(r'\W+', text_)
  14.     match_list = list()
  15.     for word in list_words.copy():
  16.         for word_compare in list_words:
  17.             if sorted(unidecode(word.lower())) == sorted(unidecode(word_compare.lower())):
  18.                 match_list.append(word_compare)
  19.                 list_words.remove(word_compare)
  20.         if len(match_list) > 1:
  21.             final.append(match_list)
  22.         match_list = list()
  23.     return final
  24.  
  25. if __name__ == '__main__':
  26.     print(anagrams(text))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement