Check if dictionary empty with == {}

Skip Montanaro skip.montanaro at
Thu Aug 20 01:41:40 CEST 2015

On Wed, Aug 19, 2015 at 6:33 PM, MRAB <python at> wrote:

> Well, that depends on the intention.
> Is it checking whether the dictionary is empty, or whether it's an
> empty dictionary (and not, say, an empty list)?

Sure, that's a possibility. I would argue that "mydict == {}" is also not
the idiomatic way to see if mydict isn't an empty list. For that, you'd use
something like

  if mydict or not isinstance(mydict, list):
     blah blah blah

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list