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?
            Asked
            
        
        
            Active
            
        
            Viewed 249 times
        
    0
            
            
        - 
                    4It sounds like you want `itertools.permutations`. Do you want every possible way to order the letters? If so then for your example you missed "ACB". – Alex Hall May 06 '18 at 09:30
- 
                    yes, i lost the acb – David Zherdenovsky May 06 '18 at 10:23
- 
                    1Step 1: Create the permutations. Step 2: Shuffle them. – Aran-Fey May 06 '18 at 10:49
1 Answers
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
