Code Explanation:
import itertools
Imports the itertools module, which provides functions for efficient looping and combinatorial operations like permutations, combinations, and product.
data = [1, 2]
Defines a list data containing two elements: [1, 2].
result = list(itertools.permutations(data))
itertools.permutations(data) generates all possible ordered arrangements (permutations) of elements in data.
Since data has two elements, the possible permutations are:
(1, 2)
(2, 1)
list() converts the result into a list of tuples.
print(result)
Prints the list of permutations.
Output
[(1, 2), (2, 1)]
0 Comments:
Post a Comment