Here is the code
def list_all(obj):
"""
Return a list of all non-list elements in obj or obj's sublists, if obj is a list. Otherwise, return a list containing obj.
@param list|object obj: object to list
@rtype: list
>>> obj = 17
>>> list_all(obj)
[17]
>>> obj = [1, 2, 3, 4]
>>> list_all(obj)
[1, 2, 3, 4]
>>> obj = [[1, 2, [3, 4], 5], 6]
>>> all([x in list_all(obj) for x in [1, 2, 3, 4, 5, 6]])
True
>>> all ([x in [1, 2, 3, 4, 5, 6] for x in list_all(obj)])
True
"""
if not isinstance(obj, list):
return obj
else:
return [list_all(x) for x in obj]
When I tried print(list_all([[2,3],[4,5]]))
, it prints out the exactly same input, meaning the code does nothing at all. I think the problem is the []
bracket but I can't think of a way to eliminate. Could someone help?