fork download
  1. def is_non_empty_array(variable):
  2. """Checks if a variable is an array (list or tuple) with at least one element.
  3.  
  4. Args:
  5. variable: The variable to check.
  6.  
  7. Returns:
  8. True if the variable is a non-empty array, False otherwise.
  9. """
  10. return isinstance(variable, (list, tuple)) and len(variable) > 0
  11.  
  12. # Example usage:
  13. my_array = [1, 2, 3]
  14. empty_array = []
  15. none_variable = None
  16.  
  17. print(is_non_empty_array(my_array)) # Output: True
  18. print(is_non_empty_array(empty_array)) # Output: False
  19. print(is_non_empty_array(none_variable)) # Output: False
Success #stdin #stdout 0.01s 7172KB
stdin
Standard input is empty
stdout
True
False
False