Testing for an empty dictionary in Python

John Nagle nagle at animats.com
Sun Mar 23 11:53:02 EDT 2008


   What's the cheapest way to test for an empty dictionary in Python?

	if len(dict.keys() > 0) :

is expensive for large dictionaries, and makes loops O(N^2).

					John Nagle



More information about the Python-list mailing list