-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
  • 714
  • 1
  • 6
  • 17

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
  • 6,456
  • 4
  • 34
  • 46