1. def validate_lists(list_of_lists):
  2. """
  3. Validates a list of lists for consistency and errors.
  4. """
  5. if not isinstance(list_of_lists, list):
  6. return "Error: Input must be a list."
  7. if not list_of_lists:
  8. return "Warning: Input list is empty."
  9. first_list_len = len(list_of_lists[0])
  10. for lst in list_of_lists:
  11. if not isinstance(lst, list):
  12. return "Error: All elements of the input list must be lists."
  13. if len(lst) != first_list_len:
  14. return f"Error: List lengths are inconsistent. Expected {first_list_len}, got {len(lst)}."
  15. for item in lst:
  16. if not isinstance(item, (int, float, str, bool, type(None))): #Allow common types
  17. return f"Error: List elements must be of type {type(lst[0]) if lst else 'any'}"
  18. return "Lists are valid."

Add your comment