You can also use quite less code, but this is less efficient: def equal_items(iter1, iter2, key=lambda x: x): class Guard(object): pass try: for x, y in izip_longest(iter1, iter2, fillvalue=Guard()): if key(x) != key(y): return False except TypeError: # intercepts key(guard) return False return True
Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list