I like Python for it's expressiveness. I can't express everything as compact as I'd like to, though. For example this one I write quite often:
def is_everything_okay(some_array):
for s in some_array:
if not is_okay(s):
return False
return True
But that's more Java then Python. How to improve the expressiveness (and probably execution speed) of that code snippet?
Use the built-in function all()
:
all(is_okay(s) for s in some_array)