looping through lists
Alex Martelli
aleax at aleax.it
Thu Oct 9 17:44:12 EDT 2003
saoirse_79 wrote:
> Thank you for your help its been great. One last
> question now that im on a roll!!
>> > Now that I have gotten my list looking like this
>> > ('-', 'K', 'S', 'A', 'K')
>> > ('-', '-', '-', 'L', 'Q')
>> > ('K', 'L', 'S', 'P', 'E')
>> > ('-', '-', '-', 'L', 'Q')
>> > ('T', 'L', 'E', 'E', 'L')
>> > I want to count the lists that dont contain a '-'.
>> > is this possible!!
>> > Orla
Look like tuples to me. Anyway,
sum([ '-' not in sublist for sublist in listoflists])
or
len([sublist for sublist in listoflists if '-' not in sublist])
might be what you want.
Alex
More information about the Python-list
mailing list