On Tue, 14 Nov 2023 at 10:00, Dom Grigonis via Python-list <python-list@python.org> wrote: > > I am not asking. Just inquiring if the function that I described could be > useful for more people. > > Which is: a function with API that of `all` and `any` and returns `True` if > specified number of elements is True. > > It is not a generalised `xor` in strict programatic space. I.e. NOT bitwise > xor applied to many bits. > This is more in line with cases that `any` and `all` builtins are used. >
A generalization of XOR is exactly what Grant and I said, though: a parity check. See for example: https://en.wikipedia.org/wiki/Exclusive_or https://reference.wolfram.com/language/ref/Xor.html It tells you whether you have an odd or even number of true values. Now, if you want something that short-circuits a counting function, that's definitely doable, but it's a sum-and-compare, not xor. Also, it's quite specialized so it's unlikely to end up in the stdlib. ChrisA -- https://mail.python.org/mailman/listinfo/python-list