Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://github.com/Vikka/python_test_ground/blob/master/exo_lou/anagrammes.md
- from unidecode import unidecode
- from re import split
- text = "A Tanger, le gérant, sans argent, ne put acheter de grenat. Le maire" \
- " et Marie, à l'aube, lui en donnèrent un beau."
- def anagrams(text_):
- final = list()
- list_words = split(r'\W+', text_)
- match_list = list()
- for word in list_words.copy():
- for word_compare in list_words:
- if sorted(unidecode(word.lower())) == sorted(unidecode(word_compare.lower())):
- match_list.append(word_compare)
- list_words.remove(word_compare)
- if len(match_list) > 1:
- final.append(match_list)
- match_list = list()
- return final
- if __name__ == '__main__':
- print(anagrams(text))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement