Open
Description
Full demo code:
from more_itertools import iequals
from unittest.mock import ANY
print([] == [ANY])
print(iequals([], [ANY]))
Output:
False
True
The mistake is that it assumes that no element will equal the fillvalue=object()
:
def iequals(*iterables):
return all(map(all_equal, zip_longest(*iterables, fillvalue=object())))
Btw, while we're at it, we could perhaps also optimize it. Zipping produces tuples, which all_equal
doesn't take advantage of. Something like this could be faster:
def iequals(*iterables):
others = len(iterables) - 1
if others < 1:
return True
for count in map(tuple.count, zip(*iterables[1:]), iterables[0]):
if count != others:
return False
return True
(This doesn't deal with length differences yet and isn't polished, either, I only wanted to point out the count way of doing this.)