Is there a way to store the results obtained using itertools?

Asked 2 years ago, Updated 2 years ago, 15 views

from itertools import permutations a=permutations(['1','2','3'],3) for i in a: print(i)

Using the

('1', '2', '3') ('1', '3', '2') ('2', '1', '3') ('2', '3', '1') ('3', '1', '2') ('3', '2', '1')

That's what I got.

Is there a way to save those results as an array or dictionary?

I'm sorry if it's too basic

python

2022-09-22 20:22

1 Answers

from itertools import permutations
a = permutations(['1','2','3'],3)
arr = []
for i in a:
    arr.append(i)

print(arr)

from itertools import permutations
a = permutations(['1','2','3'],3)
my_list = list(a)

print(my_list)


2022-09-22 20:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.