Reputation: 29
how can i make an anagram of a word using random.shuffle? so far I have this this comes up with a error message:any help is very much appreciated:
import random
word = "house"
random.shuffle(word)
print(word)
Upvotes: 1
Views: 1994
Reputation: 36
The function shuffle in the random module shuffles in-place, so you first have to convert your string to a list of characters, shuffle it, then join the result again.
import random
word = "house"
l = list(word)
random.shuffle(l)
result = ''.join(l)
print(result)
Upvotes: 2