Testing for an empty dictionary in Python

Paul Rubin http
Sun Mar 23 18:45:38 CET 2008

John Nagle <nagle at animats.com> writes:
>    What's the cheapest way to test for an empty dictionary in Python?
> 	if len(dict.keys() > 0) :

I like to think len(dict) is constant time but I haven't checked the code.
Same for bool(dict) (which is what you get when you run "if dict: ...").

More information about the Python-list mailing list