excpetions.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import re
  4. import random
  5. dictee_file = open("dictee-2005.txt", "r")
  6. dictee_text = dictee_file.read()
  7. dictee_genetic = dictee_text
  8. # print(dictee_text)
  9. dictee_text_clean = re.sub('\n+', ' ', dictee_text)
  10. dictee_text_clean = re.sub(r'\(.+\)', '', dictee_text_clean)
  11. # print(dictee_text_clean)
  12. words = dictee_text_clean.split(' ')
  13. # print(words)
  14. clean_words = []
  15. for word in words:
  16. clean_word = re.sub(r'[^\w\s]', '', word)
  17. if len(clean_word) :
  18. clean_words.append(clean_word)
  19. # print(clean_words)
  20. genetic_words = {}
  21. for word in clean_words:
  22. # print(word)
  23. genetic_words[word] = []
  24. for c in word:
  25. # print(ord(c))
  26. genetic_words[word].append(ord(c))
  27. print(genetic_words)
  28. for g_word in genetic_words:
  29. # print(g_word)
  30. # print("len",len(genetic_words[g_word]))
  31. l = random.randint(0, len(genetic_words[g_word])-1)
  32. # print("l", l)
  33. genetic_words[g_word][l] = genetic_words[g_word][l]+1
  34. print(genetic_words)
  35. for g_word in genetic_words:
  36. print(g_word)
  37. word = ""
  38. for c in genetic_words[g_word]:
  39. print(c)
  40. word+=chr(c)
  41. print(word)
  42. dictee_genetic = dictee_genetic.replace(g_word, word)
  43. print(dictee_genetic)
  44. with open('export.txt', 'w') as f:
  45. f.write(dictee_genetic)