0

let's say for example that I got 100 random words (not even real words just words)... like "ABCD" and I want to make a program that takes a word like the one I mentioned and prints you all the options of this word in random order. for example the word "ABC" will print: "ABC", "BAC", CAB", "BCA", "CBA". I could do it manually but if I have 100 words I can't... so how do I write a code that does it in python?

1 Answers1

1

You can do this by using itertools:

import itertools
import random

words = ['word1', 'word2', 'word3']

for word in words:
    permutations_list = [''.join(x) for x in itertools.permutations(word)]
    random.shuffle(permutations_list)
    print(permutations_list)
Daniele Murer
  • 247
  • 3
  • 9