Lisp mentality vs. Python mentality

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sun Apr 26 08:20:04 EDT 2009


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



More information about the Python-list mailing list