New answers tagged

2

Some quick remarks Follow the naming standards. Property names etc. should not contain anything but alphanumeric characters. No underscores etc. Use meaningful names. "OA" is meaningless, "OA_Plus" is even more confusing. A class name shouldn't be a plural (some exceptions apply): Borders. So many magic strings. "All" ...


5

NOTE: Since you provided more information about your actual problem, this answer will be very different to the already existing answers. Their pieces of advice are still valid : you really shouldn't break any(). Your actual problem However, this will execute the query an load all records into RAM, which I want to avoid As mentioned in this answer, you ...


7

Benchmarks and a faster solution Code including the solutions at the end. And note I also have an image further down that might be worth checking out before/while reading. Empty iterable First an empty iterable, as that's what motivated the question in the first place, and perhaps that also suggests that that happens non-negligibly often in what the OP is ...


9

Any and All If you are going to override any(...) to return a custom result when given an empty iterable, you should also override all(...) to return a custom result as well, for consistency. Detecting the Empty Iterable This code: count = 0 for count, item in enumerate(iterable, start=1): if item: return True return count ==...


13

I really think this is a bad idea. A function called any returning True if there not only isn't anything true but even not anything at all... that's just wrong. It sure isn't a "generalization". Shadowing the built-in is not a good idea, either. Maybe just call yours any_or_empty (without a default)? For the emptiness check, the counting seems like ...


Top 50 recent answers are included