Exercise 32
Write a program in Python that returns all the lists obtained by swapping the terms of a given list.Solution
"""import itertools module :
This module implements many iterator bricks inspired by APL, Haskell and SML constructs.
"""
import itertools
# Example of use
l = [1,2,3,4,5]
permutations = itertools.permutations(l)
L = list(permutations)
print("All lists obtained by swapping the terms of list l : " , L)
Younes Derfoufi
No comments:
Post a Comment