Fine, I reverted the edits in this topic. I hope you’re at least fine with the addition of this:
Oh, I thought you meant it could be hard to implement the full syntax I was describing. So, I was wondering if it would be easier to start with a simplified syntax.
After thinking about this more, it only needs to return a truthy value, so [True] & [] are fine too. I hope this gives it a better chance at succeeding. See the GitHub repository for more information.
Of all the ways to achieve this, there is no notation that is better than the others in every respect.
There is a trade-off between speed and brevity, the more code you use the faster it gets.
I updated this on the GitHub repository as well.
And as stated previously, replacing all uses of all() & any() where speed matters is not ideal. We’re making the code longer and you can’t inline a for loop or return a value to the outer loop. This is regression instead of progression.
But it’s suprising common as far as I can tell from my basic GitHub search.
Not happening, but you probably already knew that:
I think that’s even more confusing than the syntax I’m proposing and “until” reads like “while not”.
Fixed, it returns an iterable now.
Is just in time compilation the solution to everything now?
Hmm, with tuple comprehensions it would be even faster:
2.55x (2.39x) slower for 1 item
1 item
1000000 loops, best of 5: 352 nsec per loop
1000000 loops, best of 5: 352 nsec per loop
1000000 loops, best of 5: 330 nsec per loop
1000000 loops, best of 5: 336 nsec per loop
2000000 loops, best of 5: 138 nsec per loop
2000000 loops, best of 5: 138 nsec per loop
2.29x (1.69x) slower for 10 items
10 items
500000 loops, best of 5: 644 nsec per loop
500000 loops, best of 5: 653 nsec per loop
500000 loops, best of 5: 475 nsec per loop
500000 loops, best of 5: 477 nsec per loop
1000000 loops, best of 5: 281 nsec per loop
500000 loops, best of 5: 282 nsec per loop
2.13x (1.11x) slower for 100 items
100 items
100000 loops, best of 5: 3.39 usec per loop
100000 loops, best of 5: 3.41 usec per loop
200000 loops, best of 5: 1.76 usec per loop
200000 loops, best of 5: 1.76 usec per loop
200000 loops, best of 5: 1.59 usec per loop
200000 loops, best of 5: 1.59 usec per loop
1.73x (1.02x) slower for 1000 items
1000 items
5000 loops, best of 5: 40.3 usec per loop
5000 loops, best of 5: 40.6 usec per loop
10000 loops, best of 5: 23.7 usec per loop
10000 loops, best of 5: 23.7 usec per loop
10000 loops, best of 5: 23.3 usec per loop
10000 loops, best of 5: 23.5 usec per loop
BUT, tuple comprehensions should only be added if there are other use cases.
While the increased performance is nice, it’s not required for this proposal.
It’s not used anywhere in the stdlib and undocumented. You can only find this on StackOverflow if you compared the performance of all(... for ... in ...) / any(... for ... in ...) with a for loop.
What looks the cleanest? I think 2 (not 13) extra characters is a fine price to pay for the best performance:
if all(value in values for values in values_list)
if [value in values for each values in values_list]
if all(False for values in values_list if value not in values)
I think the performance improvement over the most commonly used variant should at least be mentioned. I can put the fasted alternative first though.
Or of efficiency simply not being as important as readability. Not every optimisation is critical - after all, if they were we’d all be writing assembler.