[Python-ideas] Extremely weird itertools.permutations

David Mertz mertz at gnosis.cx
Sat Oct 12 18:56:13 CEST 2013


On Sat, Oct 12, 2013 at 8:07 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> 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.
>
I hadn't thought about it, but as I read the docs for 3.4 (and it's the
same back through 2.7), not only would both of these be permissible in a
Python implementation:

  >>> list(collections.Counter({'a':2,'b':1}).elements())
  ['a', 'a', 'b']

Or:

  >>> list(collections.Counter({'a':2,'b':1}).elements())
  ['b', 'a', 'a']

But even this would be per documentation (although really unlikely as an
implementation):

  >>> list(collections.Counter({'a':2,'b':1}).elements())
  ['a', 'b', 'a']

-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131012/250ac951/attachment.html>


More information about the Python-ideas mailing list