-2

Is there a way to get all combinations of a string list?

Input: x=list("T", "H", "E")
Output: THE, TEH, HTE, HET, ETH, EHT

this is what I got so far I'm pretty new to this:

print("Enter word")
x=input()
print("your word is " + x)
print(list(x))

it just need to be sorted now.

quamrana
  • 37,849
  • 12
  • 53
  • 71

1 Answers1

0
from itertools import permutations

print([''.join(x) for x in permutations('THE')])

# ['THE', 'TEH', 'HTE', 'HET', 'ETH', 'EHT']

You can use any iterable for itertools.permutations, so 'THE' works, as well as ['T', 'H', 'E'].

Rafaó
  • 591
  • 3
  • 14