Counting How Many Times There Are Blank Lists In A List Of List
I have a list: l = [['a', []], ['b', []], ['c', []], ['d', ['e']], ['f', []], ['g', ['h']], ['i', ['j']]] I want to count how many lists have the element [] next to the first elem
Solution 1:
Here is a single line solution doing what you want
defcounting(l):
returnsum(x.count([]) for x in l)
Solution 2:
Since you require the empty list to be after the first element in each list this would work. Updated.
sum([1 for x in l if x[1]==[]])
Post a Comment for "Counting How Many Times There Are Blank Lists In A List Of List"