Lisp mentality vs. Python mentality

Arnaud Delobelle arnodel at googlemail.com
Sun Apr 26 15:20:51 CEST 2009


Arnaud Delobelle <arnodel at googlemail.com> writes:

> Another way would be:
>
> def equal_items(iter1, iter2, key=lambda x: x):
>     iter1, iter2 = iter(iter1), iter(iter2)
>     for x, y in izip(iter1, iter2):
>         if key(x) != key(y):
>             return False
>     for x, y in izip_longest(iter1, iter2):
>         return False
>     return True
>
> (untested)

Or even:

def equal_items(iter1, iter2, key=lambda x: x):
    iter1, iter2 = iter(iter1), iter(iter2)
    for x, y in izip(iter1, iter2):
        if key(x) != key(y):
            return False
    return not any(izip_longest(iter1, iter2))

(untested)

Or even:

def equal_items(iter1, iter2, key=lambda x: x):
    iter1, iter2 = iter(iter1), iter(iter2)
    if any(key(x) != key(y) for x, y in izip(iter1, iter2)):
        return False
   return not any(izip_longest(iter1, iter2))

-- 
Arnaud



More information about the Python-list mailing list