Optimizing the any function in python
oliverspohngellert.com
Optimizing the any function in python
1–8 of 8 posts
Re: Optimizing the any function in python
#2Re: Optimizing the any function in python
#3So 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?
Re: Optimizing the any function in python
#4So 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?
I 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.
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)])Re: Optimizing the any function in python
#5Earlier quoted context omitted.
I 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.
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)])
Re: Optimizing the any function in python
#6Earlier quoted context omitted.
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)])
The 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.
Re: Optimizing the any function in python
#7Earlier quoted context omitted.
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)])
The 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.
Re: Optimizing the any function in python
#8Earlier quoted context omitted.
I 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.
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)])