Optimizing the any function in python
1 point by ospohngellert 6 years ago | 7 comments- detaro 6 years agoSo you're artificially building something that's gives you some of the benefit of using a generator expression in a list expression, instead of just using a generator expression?
- ospohngellert 6 years agoI wouldn't call it artificially building something, but I suppose yes. I also find this code to be much more readable than generator code. Once you understand the function, all you have to do is pass it a function that returns a boolean.
- detaro 6 years agoHow is
harder to read thanany(function_takes_time(i) for i in range(10 ** 3))
fast_any([(lambda x: (lambda: function_takes_time(x)))(i) for i in range(10 ** 3)])
- ospohngellert 6 years agoYeah, sorry. Looking back into it looks like I was really re-inventing the wheel here. Still a fun exercise for me. Thanks :)
- ospohngellert 6 years agoThe first one is clearly easier to read than the second. However the first one is slow. I believe fast_any is easier to read than generator code.
- ospohngellert 6 years ago
- detaro 6 years ago
- ospohngellert 6 years ago