xor operator
Michael Speer
knomenet at gmail.com
Mon Nov 13 19:36:09 EST 2023
>AFAICT, it's not nothing at all to do with 'xor' in any sense.
As much as I agree that the function needn't be in the base of python, I
can easily follow the OP's logic on the function name.
With two items in the iterator, it is a standard binary exclusive or.
It is true if one of but not both of the items is true.
OP then generalized this to is exclusively one of any number of these
options are true, which is different than the repetitious binary operator
application, certainly, but is still very much an 'or' that excludes the
case of other options being true.
OP then generalized this from exclusively one truth in the set of variables
to some other specific number of truths that need be.
I expect the OP could then generalize this to a range of truthiness for the
set with a minimum and maximum allowable truthiness, and probably a key
function to extract some facet from the iterable for consideration.
I understand why you find it disagreeable, but I cannot find it necessarily
illogical, and it is easy, I think, to see what it has to do with xor.
A better name for OP's generalization, however, could likely be 'aut', from
the Latin exclusive or.
On Mon, Nov 13, 2023 at 7:20 PM Grant Edwards via Python-list <
python-list at python.org> wrote:
> On 2023-11-13, Dom Grigonis via Python-list <python-list at 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.
>
> I've got no objection to a function that counts True objects returned
> by an iterator and returns True IFF count == <N>.
>
> I've got no objection to a function that counts True objects returned
> by an iterator and returns True IFF count >= <N>.
>
> I've got no objection if that latter function short-circuits by
> stopping the iteration and returning True when it has seen <N> true
> objects.
>
> I don't recall ever having a need for such a function in the 25 years
> I've been writing Python code, but I'm not going to claim that nobody
> else has a need for such a function.
>
> I would object to that being called 'xor', and would fight to the
> death (yes, I'm being hyperbolic) the addition of a builtin with the
> name 'xor' that does what you describe.
>
> > It is not a generalised `xor` in strict programatic space.
>
> AFAICT, it's not nothing at all to do with 'xor' in any sense.
>
> > I.e. NOT bitwise xor applied to many bits. This is more in line
> > with cases that `any` and `all` builtins are used.
>
> Except the 'any' and 'all' builtins are _exactly_ the same as bitwise
> or and and applided to many bits. To do something "in line" with that
> using the 'xor' operator would return True for an odd number of True
> values and False for an even Number of True values.
>
> --
> Grant
> --
> https://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list