Re: Permutations using a recursive generator

2018-09-18 Thread Thomas Jollans
On 2018-09-18 17:05, ast wrote: > Le 18/09/2018 à 17:01, ast a écrit : >> Hello >> >> I found a smart and very concise code to >> generate all permutations of a list. >> I put it here if someone is interested to >> figure out how it works When you say "found a [...] code" I hope you mean "wrote a

Re: Permutations using a recursive generator

2018-09-18 Thread ast
Le 18/09/2018 à 17:01, ast a écrit : error: permut instead of S     yield from permut(li2, prefix+[elt]) -- https://mail.python.org/mailman/listinfo/python-list

Permutations using a recursive generator

2018-09-18 Thread ast
Hello I found a smart and very concise code to generate all permutations of a list. I put it here if someone is interested to figure out how it works def permut(li, prefix=[]): if len(li)==1: yield prefix + li else: for elt in li: li2 = li.copy()