[Python-ideas] Extremely weird itertools.permutations

TB bauertomer at gmail.com
Sat Oct 12 10:18:35 CEST 2013


On 10/12/2013 10:35 AM, Steven D'Aprano wrote:
> If you want a unique_permutations generator, that's a reasonable
> request. If you insist on changing permutations, that's unreasonable,
> firstly because the current behaviour is correct, and secondly because
> backwards compatibility would constrain it to keep the existing
> behaviour even if it were wrong.
>
I agree that backwards compatibility should be kept, but the current 
behaviour of itertools.permutations is (IMHO) surprising.

So here are my 2c: Until I tried it myself, I was sure that it will be 
like the corresponding permutations functions in Sage:

sage: list(Permutations("aba"))
[['a', 'a', 'b'], ['a', 'b', 'a'], ['b', 'a', 'a']]

or Mathematica: 
http://www.wolframalpha.com/input/?i=permutations+of+{a%2C+b%2C+a}

Currently the docstring of itertools.permutations just says "Return 
successive r-length permutations of elements in the iterable", without 
telling what happens with input of repeated elements. The full doc in 
the reference manual is better in that regard, but I think at least one 
example with repeated elements would be nice.

Regards,
TB


More information about the Python-ideas mailing list