[Python-ideas] Extremely weird itertools.permutations
Nick Coghlan
ncoghlan at gmail.com
Sat Oct 12 17:07:58 CEST 2013
On 12 Oct 2013 17:18, "Neil Girdhar" <mistersheik at gmail.com> wrote:
>
> I'm sorry, but I can't find a reference supporting the statement that the
current permutations function is consistent with the mathematical
definition. Perhaps you would like to find a reference? A quick search
yielded the book "the Combinatorics of Permutations":
http://books.google.ca/books?id=Op-nF-mBR7YC&lpg=PP1 Please look in the
chapter "Permutation of multisets".
Itertools effectively produces the permutation of (index, value) pairs.
Hence Steven's point about the permutations of a list not being
mathematically defined, so you have to decide what set to map it to in
order to decide what counts as a unique value. The mapping itertools uses
considers position in the iterable relevant so exchanging two values that
are themselves equivalent is still considered a distinct permutation since
their original position is taken into account. Like a lot of mathematics,
it's a matter of paying close attention to which entities are actually
being manipulated and how the equivalence classes are being defined :)
Hence the current proposal amounts to adding another variant that provides
the permutations of an unordered multiset instead of those of a set of
(index, value) 2-tuples (with the indices stripped from the results).
One interesting point is that combining collections.Counter.elements() with
itertools.permutations() currently does the wrong thing, since
itertools.permutations() *always* considers iterable order significant,
while for collections.Counter.elements() it's explicitly arbitrary.
Cheers,
Nick.
>
> Best,
>
> Neil
>
>
> On Sat, Oct 12, 2013 at 2:34 AM, Steven D'Aprano <steve at pearwood.info>
wrote:
>>
>> On Fri, Oct 11, 2013 at 10:55:06PM -0400, Neil Girdhar wrote:
>> > I honestly think that Python should stick to the mathematical
definition of
>> > permutations rather than some kind of consensus of the tiny minority of
>> > people here.
>>
>> So do I. And that is exactly what itertools.permutations already does.
>>
>>
>>
>> --
>> Steven
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>>
>> --
>>
>> ---
>> You received this message because you are subscribed to a topic in the
Google Groups "python-ideas" group.
>> To unsubscribe from this topic, visit
https://groups.google.com/d/topic/python-ideas/dDttJfkyu2k/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
python-ideas+unsubscribe at googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131013/1e171f83/attachment.html>
More information about the Python-ideas
mailing list