Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Help counting the total number of dictionaries inside a list thatcontain a specified key value
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="John Machin, post: 3610351"] Assuming: thelist = [etc etc etc] q = set(['1']); print q, sum(d.get('level') in q for d in thelist) q = set(['23']); print q, sum(d.get('level') in q for d in thelist) q = set(['2', '23']); print q, sum(d.get('level') in q for d in thelist) produces: set(['1']) 1 set(['23']) 3 set(['2', '23']) 7 Is that what you wanted? If you are sure that each dict will have a 'level' key, you can use d['level'] instead of d.get('level'). Cheers, John [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Help counting the total number of dictionaries inside a list thatcontain a specified key value
Top