Lisp mentality vs. Python mentality

Arnaud Delobelle arnodel at googlemail.com
Sun Apr 26 10:37:17 EDT 2009


Peter Otten <__peter__ at web.de> writes:

> Arnaud Delobelle wrote:
>
>> 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)
>
> This will fail when iter1 yields one more item than iter2. izip() then
> consumes one extra item:

Ah yes! And this is why I should have tested it.

-- 
Arnaud



More information about the Python-list mailing list