Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pythonic way to check if: all elements evaluate to False -OR- all elements evaluate to True

Tags:

I want the results of the function to be:

  • All values evaluate to False (None, 0, empty string) -> True
  • All values evaluate to True -> True
  • Every other case -> False

This is my try at it:

>>> def consistent(x):
...  x_filtered = filter(None, x)
...  return len(x_filtered) in (0, len(x))
...
>>> consistent((0,1))
False
>>> consistent((1,1))
True
>>> consistent((0,0))
True

[Bonus]

What should this function be named?