my program takes long time to look up all the list of the vocab in the file in order to print all the possible words that can be created. How can i make it read more faster by not using any import? I'm new to python by the way :( For example, i have more than 4000+ vocabs/letters/words contain in 1 file if you enter any letter, it will find all possible outcome in that file.
if the user enter: a c t b
it will display: (assuming all these 3 letters/words out of 4000+ are in that file that can be created)
ab
abc
act
here is my program
def scramble(r_letters, s_letters):
"""
Output every possible combination of a word.
Each recursive call moves a letter from
r_letters (remaining letters) to
s_letters (scrambled letters)
"""
if len(r_letters) == 0: # Base case: All letters used
words.add(s_letters)
else: # Recursive case: For each call to scramble()
# move a letter from remaining to scrambled
for i in range(len(r_letters)):
# Move letter to scrambled
tmp = r_letters[i]
r_letters = r_letters[:i] + r_letters[i+1:]
s_letters += tmp
scramble(r_letters, s_letters)
# Put letter back in remaining letters
r_letters = r_letters[:i] + tmp + r_letters[i:]
s_letters = s_letters[:-1]
if s_letters:
words.add(s_letters)