Created
February 13, 2019 08:13
-
-
Save saiyerniakhil/21e4a2c9caf0e6ab1058d14b182fb1db to your computer and use it in GitHub Desktop.
Scramble
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
sample = """ The company was also broadcasting the translations live online using a computer-synthesized voice, | |
instead of the original human interpreters’ voices. Wang took pictures and videos as evidence.""" | |
sample_mod = [] | |
sample_mod = sample.split(" ") | |
punct = [",",".",":","?","!"] | |
scrambled_list = [] | |
def scramble(word): | |
foo = list(word[1:-1]) | |
random.shuffle(foo) | |
return word[0] + ''.join(foo) + word[-1] | |
for i in sample_mod: | |
if len(i)>3: | |
if(i[-1] in punct): | |
ind = i.index(i[-1]) | |
res_str = scramble(i[0:-1]) + i[-1] | |
else: | |
res_str = scramble(i) | |
elif len(i)<=3: | |
res_str = i | |
scrambled_list.append(res_str) | |
sample_scr = ' '.join(scrambled_list) | |
print(sample_scr) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment