master.py: refactor some conditions to use any()

`A not in X (or B not in X)+` ==> `any(Q not in X for Q in (A, B, ...))`