Determine If A List Contains Other Lists
if I have a list, is there any way to check if it contains any other lists? what i mean to say is, I want to know if a list has this strcuture: [] as opposed to this structure [[]]
Solution 1:
any(isinstance(el, list) for el in input_list)
Solution 2:
You can take phihag's answer even further if you actually want a list of all the lists inside the list:
output_list = filter( lambda x: isinstance(x,list), input_list)
Solution 3:
lst1 in lst2
Yields True iff lst1 is in lst2.
Post a Comment for "Determine If A List Contains Other Lists"