I'm trying to remove all empty lists from a nested list recursively.
def listcleaner(lst):
if isinstance(lst[0], int):
return listcleaner(lst[1:])
if isinstance(lst[0], list):
if len(lst[0]) == []:
lst[0].remove([])
return listcleaner(lst)
return listcleaner(lst[0])
return lst
and what I'd like the function to do is
>>> a = listcleaner([1, [], [2, []], 5])
>>> print(a)
[1, [2], 5]