Check if dictionary empty with == {}

Anton anschatten at gmail.com
Wed Aug 19 18:57:47 EDT 2015


Probably a silly question. 
Let's say I have a dictionary mydict and I need to test if a dictionary is empty.

I would use

if not mydict:
    """do something"""

But I just came across a line of code like:

if mydict == {}:
    """do something"""

which seems odd to me, but maybe there is a valid use case, thus I decided to ask the community.

Thanks.




More information about the Python-list mailing list