How to from this list:
list = [
[],
['', 'subitem'],
[[]],
'item',
[
'item',
'item',
[''],
[]
],
[]
]
I can get this:
list = [
['subitem'],
'item',
[
'item',
'item'
]
]
How do I remove recursively all empty nested lists, zero-strings, and lists with nested zero-strings?
Recursion:
def remove_lst(lst):
if not isinstance(lst, list):
return lst
else:
return [x for x in map(remove_lst, lst) if (x != [] and x != '')]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With