Permutations: Difference between revisions

m
m (useless, see PEP-227 & PEP-3104)
Line 2,986:
yield from sub(0)</lang>
 
These two solutions make use of a generator, and "yield from" introduced in [https://www.python.org/dev/peps/pep-0380/ PEP-380]. They are slightly different: the latter produces permutations in lexicographic order, because the "remaining" part of a (that is, a[i+1:]) is always sorted, whereas the former always reverses the exchange just after the recursive call.
 
On three elements, the difference can be seen on the last two permutations:
Anonymous user