Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there any way to make an element in a list equal all integers?

I am trying to get these two list to equal one another:

a = [None, 3, 4, 5, 8, 9, None, 0, -3, 2, None, None, None]
b = [0, 3, 4, 5, 8, 9, 0, 0, -3, 2, 0, 0, 0]
if a == b:
    print("yay or sth")

Currently I have None as a placeholder.
other than using a for loop and checking every single one, is there any way to achieve that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

== is supposed to be transitive: if a == b and b == c, then a == c. But such a placeholder would violate that.

Better to simplify define another function to make the comparison you want instead of making __eq__ do something it should not.

def basically_equal(l1, l2):
    return all(x is None or y is None or x == y for x, y in zip(l1, l2))

if basically_equal(a, b):
    print("a and b equal up to placeholder values")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading