T
Tom Anderson
Hi all,
This is a little function to compare two iterators:
def icmp(a, b):
for xa in a:
try:
xb = b.next()
d = cmp(xa, xb)
if (d != 0):
return d
except StopIteration:
return 1
try:
b.next()
return -1
except StopIteration:
return 0
It's modelled after the way cmp treats lists - if a and b are lists,
icmp(iter(a), iter(b)) should always be the same as cmp(a, b).
Is this any good? Would it be any use? Should this be added to itertools?
tom
This is a little function to compare two iterators:
def icmp(a, b):
for xa in a:
try:
xb = b.next()
d = cmp(xa, xb)
if (d != 0):
return d
except StopIteration:
return 1
try:
b.next()
return -1
except StopIteration:
return 0
It's modelled after the way cmp treats lists - if a and b are lists,
icmp(iter(a), iter(b)) should always be the same as cmp(a, b).
Is this any good? Would it be any use? Should this be added to itertools?
tom