3

I have 3 lists out of which 1 is empty. I want to take count of lists in a list which are not empty.

For example:

 a = ['username', 'username', 'social']
 b = []
 c = ['username', 'instead', 'added']

Combining all the lists together:

combine = [a,b,c]

Counting the non-empty lists:

count = sum(x is not '' for x in combine)

When I am running the above code, I have getting 'count=3' but I want 'count=2'

Please help me how should this can be done.

adi5257
  • 83
  • 7

1 Answers1

2

try

count =sum(len(x)>0 for x in combine)

Ofir
  • 8,194
  • 2
  • 29
  • 44