On 2015-08-19 15:57, Anton wrote:
> 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.

The only valid reason is "the person who wrote that line doesn't
speak idiomatic Python", and that it should be changed to "if not
mydict" at your next code checking :-D

-tkc



-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to