+ 3
How easy way to find the permutation in python ?
2 Respuestas
+ 4
I Googled this in under 5 seconds:
https://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-JUMP_LINK__&&__python__&&__JUMP_LINK?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
Please try to do SOME research before asking.
+ 1
the simplest approach i know is by using the itertool module.
# A Python program to print all
# permutations using library function
from itertools import permutations
# Get all permutations of [1, 2, 3]
perm = permutations([1, 2, 3])
# Print the obtained permutations
for i in list(perm):
print (i)
output:
(1, 2, 3)
(1, 3, 2)
(2, 1, 3)
(2, 3, 1)
(3, 1, 2)
(3, 2, 1)