D
D
darknet372017-02-17 12:55:49
Software and Internet Services
darknet37, 2017-02-17 12:55:49

Is there a program for iterating words?

You need a program to enumerate words.
What would she do like this:
word1 word2 word3 word4
And in the end it was:
word1 word2 word4 word3
word1 word2 word4 word3
word1 word3 word4 word2
word1 word4 word3 word2
word2 word3 word1 word4
And so on.
Thank you very much in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chupasaurus, 2017-02-17
@chupasaurus

Python 2.6+

import itertools,sys
print('\n'.join([' '.join(a) for a in list(itertools.permutations(sys.argv[1:]))]))

Actually, permutations are generated into a list via itertools.permutations () (a nested list is obtained), then the options are translated into lines (words are separated by a space), separated by a line break.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question