Help counting the total number of dictionaries inside a list that contain a specified key value

Christian Heimes lists at cheimes.de
Tue Aug 12 08:32:59 EDT 2008


Jon Bowlas wrote:
> I'm afraid I can't use Peters suggestion as I'm using python 2.3 and
> it doesn't have the collection module. Thanks anyway.

Python 2.3 is the reason. It doesn't support the generator expression 
syntax. Try sum([u'Level 2 Courses' in dct for dct in yourlist]) or 
len([1 for dct in yourlist if u'Level 2 Courses' in dct])

Christian




More information about the Python-list mailing list