liste_permutations.py

Created by nicolas-patrois

Created on June 09, 2018

204 Bytes

Lists all the permutations of 𝔖n with recursive iterators.


def liste(l):
 if len(l)==1:
  yield l
 for i in range(len(l)):
  for ll in liste(l[:i]+l[i+1:]):
   yield [l[i]]+ll

def perm(n):
 for l in liste(list(range(1,n+1))):
  print(l)