Nineteendo
(Nice Zombies)
May 19, 2024, 9:07pm
101
What do you mean? I’m not counting anything.
It’s no syntax, but it will be special cased. Calling it on a regular generator still works.
I don’t like that either, but it’s difficult to do this without adding new syntax or keywords.
Sounds interesting, sadly that probably requires a __future__
import, which can’t be used in older code:
try:
from __future__ import some_awesome_new_feature
except:
pass
# SyntaxError: from __future__ imports must occur at the beginning of the file
dg-pb
(dg-pb)
May 19, 2024, 9:48pm
102
I take back half of what I said.
How would that work?
My mistake, I took your Example 3 for something other than it is. By the way, it will always evaluate to False
. Something more realistic would be better in its place.
Is there no other way to achieve optimization your are aiming at without new syntax introduction?
Nineteendo
(Nice Zombies)
May 20, 2024, 7:02am
103
Updated:
result = (value < 0 for values in values_list if len(values) > 5
for value in values).any()
Again, it’s no new syntax, just a method on a literal. I don’t see a way for them to even match the performance of a for loop if they’re builtins.