Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95498
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2015-08-19 15:57 -0700 |
| Message-ID | <af138426-3eb4-4b72-aa0f-45ce7fc5c292@googlegroups.com> (permalink) |
| Subject | Check if dictionary empty with == {} |
| From | Anton <anschatten@gmail.com> |
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.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Check if dictionary empty with == {} Anton <anschatten@gmail.com> - 2015-08-19 15:57 -0700
Re: Check if dictionary empty with == {} MRAB <python@mrabarnett.plus.com> - 2015-08-20 00:33 +0100
Re: Check if dictionary empty with == {} Tim Chase <python.list@tim.thechases.com> - 2015-08-19 18:21 -0500
Re: Check if dictionary empty with == {} Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-08-20 13:16 +1000
Re: Check if dictionary empty with == {} Steven D'Aprano <steve@pearwood.info> - 2015-08-21 03:44 +1000
Re: Check if dictionary empty with == {} Laurent Pointal <laurent.pointal@free.fr> - 2015-08-20 17:56 +0200
csiph-web