M
M
maryaturova2020-06-10 19:03:52
Python
maryaturova, 2020-06-10 19:03:52

How to get all permutations of array elements?

The essence of the problem is as follows:
there is an array .
arr = [a,b,c,d]
I need to iterate (change) it so that I get all the options for the arrangement of elements,
#a,b,c,d
#a,b,d,c
#a,c,b,d
#a,c ,d,b
etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-06-10
@maryaturova

import itertools

for variant in itertools.permutations([a, b, c, d]):
    print(variant)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question