Re: xor operator (DEPRECATED)

2023-11-13 Thread Dom Grigonis via Python-list
Thank you, I have spent a fair bit of time on these and found optimal solutions (at least I think so), but they are still multiple times slower than python builtin function. I am currently out of ideas, maybe will dig something out in time. > On 14 Nov 2023, at 07:23, Thomas Passin via

Re: xor operator (DEPRECATED)

2023-11-13 Thread Thomas Passin via Python-list
On 11/13/2023 11:44 PM, AVI GROSS via Python-list wrote: Dom, I hear you. As you say, writing your own extension in something like C++ may not appeal to you even if it is faster. I was wondering if using a generator or something similar in R might make sense. I mean what happens if you

RE: xor operator (DEPRECATED)

2023-11-13 Thread AVI GROSS via Python-list
Dom, I hear you. As you say, writing your own extension in something like C++ may not appeal to you even if it is faster. I was wondering if using a generator or something similar in R might make sense. I mean what happens if you write a function that includes a "yield" or two and does a

Re: xor operator (DEPRECATED)

2023-11-13 Thread Dom Grigonis via Python-list
Fair point. However, I gave it a shot for the following reason: I couldn’t find a way to make such performant function. Using python builtin components still ends up several times slower than builtin `all`. Cython or numba or similar is not an option as they do not support `truth` values. Or if

RE: xor operator

2023-11-13 Thread AVI GROSS via Python-list
I was going to ask a dumb question. Has any other language you know of made something available that does what is being asked for and included it in the main program environment rather than an add-on? A secondary mention here has been whether short-circuiting functions like "any" and "all" have

Re: xor operator

2023-11-13 Thread Grant Edwards via Python-list
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

Re: xor operator

2023-11-13 Thread Chris Angelico via Python-list
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

Re: xor operator

2023-11-13 Thread Alan Gauld via Python-list
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

Re: xor operator

2023-11-13 Thread Chris Angelico via Python-list
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 --

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
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

Re: xor operator

2023-11-13 Thread Chris Angelico via Python-list
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 > >

Re: xor operator

2023-11-13 Thread Michael Speer via Python-list
>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

Re: xor operator

2023-11-13 Thread Mats Wichmann via Python-list
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

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
> 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

Re: xor operator

2023-11-13 Thread Grant Edwards via Python-list
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

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
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

Re: xor operator

2023-11-13 Thread Chris Angelico via Python-list
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. > >

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
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

Re: xor operator

2023-11-13 Thread Grant Edwards via Python-list
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

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
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:

Re: xor operator

2023-11-13 Thread Chris Angelico via Python-list
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

Re: xor operator

2023-11-13 Thread Axel Reichert via Python-list
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

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
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

Re: xor operator

2023-11-13 Thread MRAB via Python-list
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

Re: xor operator

2023-11-13 Thread Michael Speer via Python-list
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

Re: xor operator

2023-11-13 Thread Barry via Python-list
> 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 --

Re: xor operator

2023-11-13 Thread Dom Grigonis via Python-list
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.

Re: No current way to just compile flet code into truly native packages for smart phones, etc.?

2023-11-13 Thread Barry via Python-list
> On 13 Nov 2023, at 17:21, Jacob Kruger via Python-list > wrote: > > Had a look at the following bit of introduction to using python and flet to > build cross-platform flutter-based apps using same python code, and, while it > seems to work alright if tell it to run as under GUI here on

Re: xor operator

2023-11-13 Thread Barry via Python-list
> 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

No current way to just compile flet code into truly native packages for smart phones, etc.?

2023-11-13 Thread Jacob Kruger via Python-list
Had a look at the following bit of introduction to using python and flet to build cross-platform flutter-based apps using same python code, and, while it seems to work alright if tell it to run as under GUI here on windows desktop, and, while can get it to fire up PWA version as well, that's

xor operator

2023-11-13 Thread Dom Grigonis via Python-list
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 complete flexibility 3rd argument could indicate if `the

Re: SQL rollback of multiple inserts involving constraints

2023-11-13 Thread Loris Bennett via Python-list
Jacob Kruger writes: > Think performing a session/transaction flush after the first two > inserts should offer the workaround before you've committed all > transaction actions to the database finally: > >