icmp - should this go in itertools?
Tom Anderson
twic at urchin.earth.li
Sat Nov 26 15:41:10 EST 2005
On Sat, 26 Nov 2005, Diez B. Roggisch wrote:
> Tom Anderson wrote:
>
>> Is this any good? Would it be any use? Should this be added to itertools?
>
> Whilst not a total itertools-expert myself, I have one little objection
> with this: the comparison won't let me know how many items have been
> consumed. And I end up with two streams that lack some common prefix
> plus one field.
Good point. It would probably only be useful if you didn't need to do
anything with the iterators afterwards.
One option - which is somewhat icky - would be to encode that in the
return value; if n is the number of items read from both iterators, then
if the first argument is smaller, the return value is -n, and if the
second is smaller, it's n. The trouble is that you couldn't be sure
exactly how many items had been read from the larger iterator - it could
be n, if the values in the iterators differ, or n+1, if the values were
the same but the larger one was longer.
> I'm just not sure if there is any usecase for that.
I used it in my ordered dictionary implementation; it was a way of
comparing two 'virtual' lists that are lazily generated on demand.
I'll go away and think about this more.
tom
--
Gotta treat 'em mean to make 'em scream.
More information about the Python-list
mailing list