[Python-ideas] Possible new itertool: comm()
Paul Moore
p.f.moore at gmail.com
Tue Jan 6 17:44:04 CET 2015
On 6 January 2015 at 16:33, Ian Cordasco <graffatcolmingov at gmail.com> wrote:
> So my question is how well with this work with generators/iterators?
> Your examples use lists, but it would be impossible to use this with
> anything that isn't finite right?
The examples use lists because I was using doctest and needed
checkable output. But I think it should work fine with any (finite)
iterator. I don't see a problem with the algorithm if I use infinite
iterators (the algorithm is one-pass and generates results on demand)
but I haven't tested it explicitly.
[pause, test...]
Yep, looks OK:
>>> import itertools
>>> c1 = itertools.count()
>>> c2 = itertools.count(3)
>>> output = comm(c1, c2)
>>> next(output)
('<', 0)
>>> next(output)
('<', 1)
>>> next(output)
('<', 2)
>>> next(output)
('=', 3)
Paul
More information about the Python-ideas
mailing list