Scrambled words: the rset can be a toatl mses and you can sitll raed it wouthit porbelm

posted Feb 15, 2019, 8:05 AM by Attila Lengyel
import random
def randomize(word):
if len(word) < 3:
return word
chars = []
for i in word: #this stores every characters in a list
chars.append(i)
result =[]
result.append(chars[0]) # stores the first character
del chars[0] #deletes from the list
result.append(chars[len(chars)-1]) # stores the last character
del chars[len(chars)-1] #delets the last character
while len(chars) != 0:
r = random.randint(0,len(chars)-1)
result.insert(1, chars[r]) #inserts into the second position
del chars[r]
randomword = ""
for i in result: #appends the random list of characters
randomword += i
return randomword #returns randomword

text = "the rest can be a total mess and you can still read it without problem"
sentance = ""
for i in text.split(" "):
sentance += randomize(i) + " "
print(sentance)

Comments