Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Function to generate all strings for the word wrangler game
- def gen_all_strings(word):
- """
- Generate all strings that can be composed from the letters in word
- in any order.
- Returns a list of all strings that can be formed from the letters
- in word.
- This function should be recursive.
- """
- if word == "":
- return [""]
- else:
- first = word[0]
- rest_word = word[1:]
- rest_strings = gen_all_strings(rest_word)
- all_strings = []
- for string in rest_strings:
- for letter_pos in range(len(string) +1):
- all_strings.append(string[0:letter_pos] + \
- first + string[letter_pos:])
- return all_strings + rest_strings
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement