-2

I have a string "dog" and I wan't to generate all possible combinations with letters from that word.

Output would be something like this:

["dog","dgo","ogd","odg","god","gdo"]

Order does not matter at all.

Ciprum
  • 734
  • 1
  • 11
  • 18

1 Answers1

2

Use itertools.permutations:

import itertools

word = 'dog'
result = [''.join(new_word) for new_word in itertools.permutations(word)]

print(result)
Dima Kudosh
  • 7,126
  • 4
  • 36
  • 46