<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">> Moreover, I don't think the runtime behavior of my one-liner is particularly costly…</span><div><br></div><div>It is *extremely* costly.  There can be n! permutations, so for even, say, 12 elements, you are looking at many gigabytes of memory needlessly used.  One big motivator for itertools is not to have to do this.  I'm curious how you would solve this problem: <a href="https://www.kattis.com/problems/industrialspy">https://www.kattis.com/problems/industrialspy</a>  efficiently in Python.  I did it by using a unique-ifying generator, but ideally this would not be necessary.  Ideally, Python would do exactly what C++ does with next_permutation.</div>

<div><br></div><div>Best,</div><div><br></div><div>Neil</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Oct 11, 2013 at 4:27 PM, David Mertz <span dir="ltr"><<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Andrew & Neil (or whoever):<div><br></div><div>Is this *really* what you want:</div><div><br></div>
<div>
<div>>>> from itertools import permutations</div><div>>>> def nonredundant_permutations(seq):</div>
<div>...     return list(set(permutations(seq)))<br></div><div>...</div><div><div>>>> pprint(list(permutations([F(3,1), D(3.0), 3.0])))</div><div>[(Fraction(3, 1), Decimal('3'), 3.0),</div><div> (Fraction(3, 1), 3.0, Decimal('3')),</div>


<div> (Decimal('3'), Fraction(3, 1), 3.0),</div><div> (Decimal('3'), 3.0, Fraction(3, 1)),</div><div> (3.0, Fraction(3, 1), Decimal('3')),</div><div> (3.0, Decimal('3'), Fraction(3, 1))]</div>


<div><br></div><div>>>> pprint(list(nonredundant_permutations([F(3,1), D(3.0), 3.0])))</div><div>[(Fraction(3, 1), Decimal('3'), 3.0)]</div></div></div><div><br></div><div>It seems odd to me to want that.  On the other hand, I provide a one-line implementation of the desired behavior if anyone wants it.  Moreover, I don't think the runtime behavior of my one-liner is particularly costly... maybe not the best possible, but the best big-O possible.</div>


<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div class="im">On Fri, Oct 11, 2013 at 1:19 PM, Andrew Barnert <span dir="ltr"><<a href="mailto:abarnert@yahoo.com" target="_blank">abarnert@yahoo.com</a>></span> wrote:<br>


</div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>I think equality is perfectly reasonable here. The fact that {3.0, 3} only has one member seems like the obvious precedent to follow here.<br>


<br>Sent from a random iPhone</div><div><div><div><br>On Oct 11, 2013, at 13:02, David Mertz <<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>> wrote:<br><br></div><blockquote type="cite">
<div><div dir="ltr">What would you like this hypothetical function to output here:<br><div class="gmail_quote"><div dir="ltr"><div><br></div><div><div>>>> from itertools import permutations</div><div>>>> from decimal import Decimal as D<br>



</div><div>>>> from fractions import Fraction as F<br>
</div><div>>>> items = (3, 3.0, D(3), F(3,1), "aa", "AA".lower(), "a"+"a")<br></div><div>>>> list(permutations(items))<br></div></div><div><br></div><div>It's neither QUITE equality nor identity you are looking for, I think, in nonredundant_permutation():</div>




<div><br></div><div><div>>> "aa" == "AA".lower(), "aa" is "AA".lower()</div><div>(True, False)</div></div><div><div>>>> "aa" == "a"+"a", "aa" is "a"+"a"</div>




<div>(True, True)</div></div><div><div>>>> D(3) == 3.0, D(3) is 3.0</div><div>(True, False)</div></div><div><br></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>On Fri, Oct 11, 2013 at 11:38 AM, Neil Girdhar <span dir="ltr"><<a href="mailto:mistersheik@gmail.com" target="_blank">mistersheik@gmail.com</a>></span> wrote:<br>




</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">"It is universally agreed that a list of n distinct symbols has n! permutations. However, when the symbols are not distinct, the most common convention, in mathematics and elsewhere, seems to be to count only distinct permutations."  — <a href="http://stackoverflow.com/questions/6534430/why-does-pythons-itertools-permutations-contain-duplicates-when-the-original" target="_blank">http://stackoverflow.com/questions/6534430/why-does-pythons-itertools-permutations-contain-duplicates-when-the-original</a>.<br>




<br><br>Should we consider fixing itertools.permutations and to output only unique permutations (if possible, although I realize that would break code).  It is completely non-obvious to have permutations returning duplicates.  For a non-breaking compromise what about adding a flag?<br>




<br>Best,<br>Neil<br></div><br></div></div><div>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br></div></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br>Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>



uneducated; technology from the underdeveloped; and putting <br>
advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br>
</font></span></div>
</div><br><br clear="all"><div><br></div>-- <br>Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>



advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br>
</div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Python-ideas mailing list</span><br><span><a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a></span><br>


<span><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a></span><br></div></blockquote></div></div></div></blockquote></div></div></div>

<div><div class="h5"><br><br clear="all">
<div><br></div>-- <br>Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>


to the 21st century what the slave trade was to the 16th.<br>
</div></div></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br>--<br>
<br>
---<br>
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.<br>
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/python-ideas/dDttJfkyu2k/unsubscribe" target="_blank">https://groups.google.com/d/topic/python-ideas/dDttJfkyu2k/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href="mailto:python-ideas%2Bunsubscribe@googlegroups.com">python-ideas+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a href="https://groups.google.com/groups/opt_out" target="_blank">https://groups.google.com/groups/opt_out</a>.<br>
<br></blockquote></div><br></div>