0 out of 464 challenges solved

Count Nested Lists

Write a Python function `count_nested_lists` that takes a list as input and returns the number of nested lists within it. A nested list is any element of the input list that is itself a list.

#### Example Usage
```python [main.nopy]
print(count_nested_lists([[1, 2], [3, 4], 5, [6]]))  # Output: 3
print(count_nested_lists([1, 2, 3]))  # Output: 0
print(count_nested_lists([[1], [2], [3], [4]]))  # Output: 4
```

#### Requirements
- The function should iterate through the input list and count elements that are of type `list`.
- Return the count as an integer.
def count_nested_lists(input_list):
    """
    Count the number of nested lists within the given list.

    Args:
        input_list (list): The list to check for nested lists.

    Returns:
        int: The count of nested lists.
    """
    # Initialize a counter for nested lists
    count = 0
    # Iterate through the input list
    for element in input_list:
        # Check if the element is a list
        if isinstance(element, list):
            # Increment the counter
            count += 1
    # Return the count
    return count