3 ms·
How is any(function_takes_time(i) for i in range(10 ** 3)) harder to read than fast_any([(lambda x: (lambda: function_takes_time(x)))(i) for i in ran
by detaro 8y ago
How is
any(function_takes_time(i) for i in range(10 ** 3))
harder to read than
fast_any([(lambda x: (lambda: function_takes_time(x)))(i) for i in range(10 ** 3)])
- ospohngellert 8y 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.
- detaro 8y agoThe first IS generator code. That's a generator expression, note that it does not have the [] of a list expression.
- ospohngellert 8y agoActually, apologies I see now. I always associated generator's with the `yields` keyword, but maybe I have to look into them again. Thanks!
- ospohngellert 8y agoYeah, sorry. Looking back into it looks like I was really re-inventing the wheel here. Still a fun exercise for me. Thanks :)