8000 `iequals([], [ANY])` returns `True` · Issue #900 · more-itertools/more-itertools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
iequals([], [ANY]) returns True #900
Open
@pochmann3

Description

@pochmann3

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    deferredWe're not inclined to fix this issue, but please link to it if the same thing comes up later

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0