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?
>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")