Reputation: 3
import random
def word_scrambler(word):
a = word[1]
b = word[2]
c = word[3]
d = word[4]
e = word[5]
f = word[6]
g = word[7]
h = word[8]
letterzz = [a,b,c,d,e,f,g]
letterz = [a,b,c,d,e,f,g,h]
letter = [a,b,c,d,e,f]
lette = [a,b,c,d,e]
lett = [a,b,c,d]
let = [a,b,c]
le = [a,b]
l = [a]
i = random.choice(l)
j = random.choice(le)
k = random.choice(let)
l = random.choice(lett)
m = random.choice(lette)
n = random.choice(letter)
o = random.choice(letterz)
p = random.choice(letterzz)
return i+j+k+l+m+n+o+p
What I am trying to do is create a word scrambler that will scramble an inputted word from the function.
I am not sure how to make it choose a random letter only once from each section of the word inputted. So like [a,b,c,d,e,f,g]
and make it pick g
only once and then it won't pick g
again in the next search, and have it do that until it has used all the letters from the inputted word to make a random string.
Upvotes: 0
Views: 48
Reputation:
import random
def word_scrambler(word):
letter_list = list(word)
random.shuffle(letter_list)
return ''.join(letter_list)
Upvotes: 1