How to check nested list in Python?

I’m working on a project in which I have to take List as input from the user and work on it. Before working, I have to check that user doesn’t provide any nested List. My code below is not working properly and giving me an error.

def is_aggregated(lst):
          return isinstance((item,list) for item in lst)
#Creating a list
my_list1 = [1, [2, 3], 4]
my_list2 = [1, [2, [3, 4]], 5]

#Checking nesting
print(is_aggregated(my_list1)) 
print(is_aggregated(my_list2))

TypeError: isinstance expected 2 arguments, got 1

Hello @safa, to check if a list is nested or not you can use modify your function and use any() to check whether any of the items in the list are themselves iterable. I am attaching a code below that implements this technique:

This function will return True if it detects an iterable (list, set, tuple, frozenset) is present as an item in the list passed to this function.