Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import copy
- import re
- def prepare_to_british_scientists(text, letters_to_shuffle_nm):
- for word in re.findall(r'\w+', text):
- line = list(word)
- if len(line) > 2:
- del line[0]
- del line[len(line) - 1]
- shuf = []
- index = 0
- to_change = min(letters_to_shuffle_nm, len(line))
- while index < to_change:
- letter = random.randint(0, len(line) - 1)
- if letter not in shuf:
- shuf.append(letter)
- index += 1
- line1 = copy.copy(line)
- for i in range(to_change):
- line1[shuf[i]] = line[shuf[(i + 1) % (to_change)]]
- res = word[0]
- for i in range(len(line1)):
- res += line1[i]
- res += word[-1]
- text = text.replace(word, res)
- return text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement