31 Dec
2019
31 Dec
'19
9:18 p.m.
if foo OR bar OR baz in foobar: pass
Someone else noted, and I agreed, that set intersection is already the obvious way to do this. But yes, some things aren't hashable. So in concept you could make a custom type that had some set-like behaviors, and so on. But all of this is crazy work for a pattern that really isn't that common, in my experience. The obvious answer doesn't disrupt anything: just write a FUNCTION: if any_in((foo, bar, baz), foobar): ... That's completely obvious and needs no change. Heck, write all_in(), most_in(), and at_least_n_in(), while you are at it. None need syntax, all variations take 2-5 lines of code each, depending on implementation.