Advertisement
DariaFil

British

May 2nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import random
  2. import copy
  3. import re
  4.  
  5.  
  6. def prepare_to_british_scientists(text, letters_to_shuffle_nm):
  7. for word in re.findall(r'\w+', text):
  8. line = list(word)
  9. if len(line) > 2:
  10. del line[0]
  11. del line[len(line) - 1]
  12. shuf = []
  13. index = 0
  14. to_change = min(letters_to_shuffle_nm, len(line))
  15. while index < to_change:
  16. letter = random.randint(0, len(line) - 1)
  17. if letter not in shuf:
  18. shuf.append(letter)
  19. index += 1
  20. line1 = copy.copy(line)
  21. for i in range(to_change):
  22. line1[shuf[i]] = line[shuf[(i + 1) % (to_change)]]
  23. res = word[0]
  24. for i in range(len(line1)):
  25. res += line1[i]
  26. res += word[-1]
  27. text = text.replace(word, res)
  28. return text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement