I have a list like below:
L = [1,2,3,[1,2],15,[1,[5,6]],[],[[]],5]
I want to add the int
values only together. I can extract the items in the nested lists but when I get to a nested list like [[]]
or empty list []
, I get IndexError: list index out of range
. How do I either skip the lists that are empty or set their value to 0
when I check them?
I tried:
l2 = [[]]
if not l2:
# do something
but this only works if the list is a single list []
.