0

I am creating a basic program to take words turn them into single characters and then scrabble all of the characters in every way possible. The only issue I am having is scrabbling the characters in everyway.

In every way possible I mean like say you have the word "the" you could have "hte" and "eth" and so on and so forth.

My code so far:

user = input("First; ")
user2 = input("Second; ")
user3 = input("Third; ")
user4 = input("Fourth; ")
user5 = input("Fifth; ")

with open("file.txt", 'r+') as file:
    file.truncate()
    file.write(user + user2 + user3 + user4 + user5)

xy = open("file.txt", "r")
yy = xy.read()
wow = list (yy)
Alec
  • 8,529
  • 8
  • 37
  • 63
CHANCESR
  • 15
  • 5
  • Possible duplicate of [Finding all possible permutations of a given string in python](https://stackoverflow.com/questions/8306654/finding-all-possible-permutations-of-a-given-string-in-python) – Alejandro Blasco May 20 '19 at 05:13

1 Answers1

0

You can use itertools.permutations to generate anagrams:

import itertools
anagrams = [''.join(x) for x in itertools.permutations(word)]

If a word contains repeated letters, you will get some duplicates. You can remedy this using set():

anagrams = list(set(anagrams))
Alec
  • 8,529
  • 8
  • 37
  • 63