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

Steven D'Aprano steve at pearwood.info
Wed Jan 7 16:38:48 CET 2015


On Wed, Jan 07, 2015 at 03:19:31PM +0100, Victor Stinner wrote:
> Hi,
> 
> 2015-01-06 18:14 GMT+01:00 Raymond Hettinger <raymond.hettinger at gmail.com>:
> >> On Jan 6, 2015, at 8:22 AM, Paul Moore <p.f.moore at gmail.com> wrote:
> >>
> >> In writing a utility script today, I found myself needing to do
> >> something similar to what the Unix "comm" utility does - take two
> >> sorted iterators, and partition the values into "only in the first",
> >> "only in the second", and "in both" groups.
> >
> > As far as I can tell, this would be a very rare need.
> 
> I never used the UNIX comm tool. I didn't know that it exists :-)
> 
> Can you maybe explain the purpose the tool/your function? Show an example.

It might help to realise that comm is abbreviated from "common". It took 
me an embarrassingly long time to work that out.

This example of using comm in Unix might help:

http://www.theunixschool.com/2011/03/comm-beautiful-comparison.html


> difflib may be a better candidate to add such function than contextlib.

I think you mean itertools rather than contextlib.

It seems to me that difflib would be a good place for it.


-- 
Steve


More information about the Python-ideas mailing list