0 out of 464 challenges solved
Write a function `count_lists_in_tuple(input_tuple)` that takes a tuple as input and returns the number of lists present in the tuple. #### Example Usage ```python [main.nopy] print(count_lists_in_tuple(([1, 2, 3], [4, 5], 6))) # Output: 2 print(count_lists_in_tuple((1, 2, 3, [4, 5], [6, 7, 8]))) # Output: 2 print(count_lists_in_tuple((1, 2, 3))) # Output: 0 ``` #### Constraints - The input will always be a tuple. - The tuple can contain elements of any type.
def count_lists_in_tuple(input_tuple): """ Count the number of lists present in the given tuple. Args: input_tuple (tuple): A tuple containing various elements. Returns: int: The number of lists in the tuple. """ # Initialize a counter for lists list_count = 0 # Iterate through the elements of the tuple for element in input_tuple: # Check if the element is a list if isinstance(element, list): # Increment the counter list_count += 1 # Return the count of lists return list_count