hi,
This is my problem i have programmed a little word unscrambler i have a file wordlist.txt in my python folder and this program works just fine and unscrambles one word at a time but i dont how how to edit it to make it unscramble 10 words at a time can someone please help??
thanks
ps i want it to print the solution in this format:
word1, word2, word3,.......all the way to word10
here is my code
ps it prints the same solution multiple times
import string
def anagrams(s):
if s == "":
return [s]
else:
ans = []
for an in anagrams(s[1:]):
for pos in range(len(an)+1):
ans.append(an[:pos]+s[0]+an[pos:])
return ans
def dictionary(wordlist):
dict = {}
infile = open(wordlist, "r")
for line in infile:
word = line.split("\n")[0]
dict[word] = 1
infile.close()
return dict
def main():
diction = dictionary("wordlist.txt")
for i in range(10):
anagram = raw_input("Please enter a words you need to unscramble: ")
anaLst = anagrams(anagram)
for ana in anaLst:
if diction.has_key(ana):
print "The solution to the jumble is", ana
main()