Testing for an empty dictionary in Python

Bryan Olson fakeaddress at nowhere.org
Mon Mar 24 03:45:54 CET 2008


D'Arcy J.M. Cain wrote:
> John Nagle  wrote:
>>    What's the cheapest way to test for an empty dictionary in Python?

> Try this:
> 
>     if dict:

D'Arcy is right; that's the way to go. I'll add that 'dict' is the name 
of the built-in class, so an instance is usually best named something else.


-- 
--Bryan



More information about the Python-list mailing list