Check if dictionary empty with == {}
Skip Montanaro
skip.montanaro at gmail.com
Wed Aug 19 19:41:40 EDT 2015
On Wed, Aug 19, 2015 at 6:33 PM, MRAB <python at mrabarnett.plus.com> 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
Skip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150819/3d3d8857/attachment.html>
More information about the Python-list
mailing list