In case someone is actually going to execute the code, there is a bug:
`set` need to be wrapped in `len` for criteria args.
> On 15 Nov 2023, at 20:13, Dom Grigonis wrote:
>
>
> The specific situation was related to truth values and following out of that
> my considerations regarding equivale
The specific situation was related to truth values and following out of that my
considerations regarding equivalent of all and any for counting `truths`.
So one of the specific examples:
class Publisher:
def __init__(self):
self.subscribers = dict()
def subscribe(self, sub, crit
On 2023-11-15 12:26:32 +0200, Dom Grigonis wrote:
>
> Thank you,
>
>
> test2 = [True] * 100 + [False] * 2
> test2i = list(range(100))
>
> %timeit len(set(test2i)) == 1 # 1.6 µs ± 63.6 ns per loop (mean ± std. dev.
> of 7 runs, 1,000,000 loops each)
> %timeit all(test2) # 386 ns
Thank you,
test2 = [True] * 100 + [False] * 2
test2i = list(range(100))
%timeit len(set(test2i)) == 1 # 1.6 µs ± 63.6 ns per loop (mean ± std. dev.
of 7 runs, 1,000,000 loops each)
%timeit all(test2) # 386 ns ± 9.58 ns per loop (mean ± std. dev.
of 7 runs, 1,000,000 loops each)
On 2023-11-14 00:11:30 +0200, Dom Grigonis via Python-list wrote:
> Benchmarks:
> test1 = [False] * 100 + [True] * 2
> test2 = [True] * 100 + [False] * 2
>
> TIMER.repeat([
> lambda: xor(test1), # 0.0168
> lambda: xor(test2), # 0.0172
> lambda: xor_ss(test1), # 0.1392
> la
stitute for the
>> non-standard evaluation in R where you can arrange for lots of your data to
>> not be interpreted till absolutely needed.
>> -Original Message-
>> From: Dom Grigonis
>> Sent: Monday, November 13, 2023 10:12 PM
>> To: avi.e.gr...@gmail.co
aluation in R where you can arrange for lots of your data to not
be interpreted till absolutely needed.
-Original Message-
From: Dom Grigonis
Sent: Monday, November 13, 2023 10:12 PM
To: avi.e.gr...@gmail.com
Cc: Grant Edwards ; Python
Subject: Re: xor operator (DEPRECATED)
Fair poin
ther.
>
> -----Original Message-
> From: Python-list On
> Behalf Of Grant Edwards via Python-list
> Sent: Monday, November 13, 2023 8:19 PM
> To: python-list@python.org
> Subject: Re: xor operator
>
> On 2023-11-14, Dom Grigonis via Python-list wrote:
>>
>&
e up with an amazing number of ideas including for
> "useful" functions or features but I find the vast majority would rarely be
> used as nobody remembers it is available and some fairly simple method using
> other functions can easily be cobbled together.
>
> -Original Message
other functions can easily be cobbled together.
-Original Message-
From: Python-list On
Behalf Of Grant Edwards via Python-list
Sent: Monday, November 13, 2023 8:19 PM
To: python-list@python.org
Subject: Re: xor operator
On 2023-11-14, Dom Grigonis via Python-list wrote:
>
>> Exc
On 2023-11-14, Dom Grigonis via Python-list wrote:
>
>> 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
On Tue, 14 Nov 2023 at 11:40, Chris Angelico wrote:
> Here's a couple of excellent videos on error correction, and you'll
> see XOR showing up as a crucial feature:
>
> https://www.youtube.com/watch?v=X8jsijhllIA
> https://www.youtube.com/watch?v=h0jloehRKas
>
I just flipped through that 3blue1br
On 14/11/2023 00:33, Mats Wichmann via Python-list wrote:
> Hardware and software people may have somewhat different views of xor
I've come at it from both sides. I started life as a telecomms
technician and we learned about xor in the context of switching
and relays and xor was a wiring configura
On Tue, 14 Nov 2023 at 12:02, Dom Grigonis via Python-list
wrote:
> As I am here, I will dare to ask if there is no way that `sign` function is
> going to be added to `math` or `builtins`.
>
https://docs.python.org/3/library/math.html#math.copysign
ChrisA
--
https://mail.python.org/mailman/lis
I agree, from perspective of standard `all` and `any` use cases this does not
seem very useful.
However, in my experience it has its usages. E.g.:
* If sum(map(bool, iterable) [> | <] n can be useful. Counting dead processes
and similar, optimisation problems where need to re-initialise if less
On Tue, 14 Nov 2023 at 11:29, Dom Grigonis via Python-list
wrote:
>
>
> > 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
> > val
>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
On 11/13/23 16:24, Dom Grigonis via Python-list wrote:
I am not arguing that it is a generalised xor.
I don’t want anything, I am just gauging if it is specialised or if there is a
need for it. So just thought could suggest it as I have encountered such need
several times already.
It is fairl
> 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.
Fair point.
Have you ever
On 2023-11-13, Dom Grigonis via Python-list 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 t
I am not arguing that it is a generalised xor.
I don’t want anything, I am just gauging if it is specialised or if there is a
need for it. So just thought could suggest it as I have encountered such need
several times already.
It is fairly clear by now that it is not a common one given it took
On Tue, 14 Nov 2023 at 10:00, Dom Grigonis via Python-list
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
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
ap
On 2023-11-13, Dom Grigonis via Python-list wrote:
> Hi All,
>
> I think it could be useful to have `xor` builtin, which has API similar to
> the one of `any` and `all`.
>
> * Also, it could have optional second argument `n=1`, which
> * indicates how many positives indicates `True` return. For
Benchmarks:
test1 = [False] * 100 + [True] * 2
test2 = [True] * 100 + [False] * 2
TIMER.repeat([
lambda: xor(test1), # 0.0168
lambda: xor(test2), # 0.0172
lambda: xor_ss(test1), # 0.1392
lambda: xor_ss(test2), # 0.0084
lambda: xor_new(test1), # 0.0116
lambda: xor_
On Tue, 14 Nov 2023 at 08:57, Axel Reichert via Python-list
wrote:
>
> Barry writes:
>
> > I do not understand how xor(iterator) works.
> > I thought xor takes exactly 2 args.
>
> See
>
> https://mathworld.wolfram.com/XOR.html
>
> for some background (I was not aware of any generalizations for
Barry writes:
> I do not understand how xor(iterator) works.
> I thought xor takes exactly 2 args.
See
https://mathworld.wolfram.com/XOR.html
for some background (I was not aware of any generalizations for more
than 2 arguments either).
> I also do not understand how xor can be short circui
xor([True, False, False, False], n=1)
xor([False, False, False, True], n=1)
Both of the above would evaluate to true.
Well, it depends how you interpret it.
In binary case it reads: “exclusively one positive bit or the other, but not
both”
In this case one could read: “exclusively one positive se
On 2023-11-13 21:03, Barry via Python-list wrote:
On 13 Nov 2023, at 17:48, Dom Grigonis wrote:
Short circuiting happens, when:
xor([True, True, False, False], n=1)
At index 1 it is clear that the answer is false.
Can you share an example with 4 values that is true?
And explain why it is x
I don't think an exclusive-or/truthy-entries-count-checker needs to be a
builtin by any stretch.
>>> def xor( iterable, n = 1 ):
... return sum( map( bool, iterable ) ) == n
Or if you insist on short circuiting:
>>> def xor_ss( iterable, n = 1 ):
... for intermediate in itertools.accumulat
> On 13 Nov 2023, at 17:48, Dom Grigonis wrote:
>
> Short circuiting happens, when:
> xor([True, True, False, False], n=1)
> At index 1 it is clear that the answer is false.
Can you share an example with 4 values that is true?
And explain why it is xor.
Barry
--
https://mail.python.org/mai
Well yes, I don’t think naming is very accurate. If iterable has 2 elements,
then it is `xor`, otherwise it is something else - it checks the number of
truth values in iterable.
Short circuiting happens, when:
xor([True, True, False, False], n=1)
At index 1 it is clear that the answer is false.
> On 13 Nov 2023, at 15:16, Dom Grigonis via Python-list
> wrote:
>
> I think it could be useful to have `xor` builtin, which has API similar to
> the one of `any` and `all`.
I do not understand how xor(iterator) works.
I thought xor takes exactly 2 args.
I also do not understand how xor c
33 matches
Mail list logo