[Python-ideas] Possible new itertool: comm()

David Mertz mertz at gnosis.cx
Wed Jan 7 19:20:22 CET 2015


Adding a itertools.comm() seems unnecessary, although adding it to the
widely used more-itertools feels more reasonable.

However, the problem with the functionality is that it assumes that the
iterables given to it return pre-sorted values.  Which is fine it that
assumption is satisfied, but one really can't know in advance of exhausting
the iterators whether that will prove true.  The desired behavior in the
absence of this pre-condition being satisfied is unclear to me.

I could plausibly see the tool raising some exception when the
pre-condition was violated.  Of course, in that case, we might well have
already returned multiple elements on next(comm(it1, it2)) calls before the
exception is encountered, and the initial values might be deceptive or
retroactively invalidated.

I could plausibly see it ignoring the non-sorted elements in some way.
Maybe just pretend they are sorted rather than checking, returning somewhat
ill-defined values, I'd think.  Or maybe just discarding the missorted
values? Or flagging them with some other indicator indicating the
missorting? I dunno.

In any case, this is not something that can be applied to iterators
generically, but only to iterators about which one makes lots of
assumptions in advance, and hence seems ill-suited for the stdlib itertools.


On Wed, Jan 7, 2015 at 8:09 AM, Paul Moore <p.f.moore at gmail.com> wrote:

> On 7 January 2015 at 15:38, Steven D'Aprano <steve at pearwood.info> wrote:
> > This example of using comm in Unix might help:
> >
> > http://www.theunixschool.com/2011/03/comm-beautiful-comparison.html
>
> The example on that page is the exact reason I wrote my own
> implementation (the Windows version of comm that I have locally got
> confused by non-ASCII content in some of the filenames I had).
>
> Paul
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
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/20150107/03368b87/attachment.html>


More information about the Python-ideas mailing list