Differance_dictionnaire~20171216-220411.py 661 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. diff_words = []
  4. #Créez un dictionnaire
  5. permutations = {
  6. 'ph' : 'f' ,
  7. 'qu' : 'kh' ,
  8. 'y' : 'i' ,
  9. 't' : 'th' ,
  10. 'ê' : 'ai' ,
  11. 'ss' : 'ç' ,
  12. }
  13. #Ouvrir un texte comme matériau brut
  14. #Le séparer en lignes
  15. #le séparer en mots
  16. with open("diff.txt", "r", encoding="ISO-8859-1") as source:
  17. for line in source:
  18. words = line.split(" ")
  19. for word in words:
  20. for key, value in permutations.items():
  21. if key in word:
  22. word = word.replace(key, value)
  23. diff_words.append(word)
  24. with open("diff_permute.txt", "w") as destination:
  25. destination.write(' '.join(diff_words))