Path: csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; '"if': 0.09; 'python",': 0.09; 'question.': 0.13; '-tkc': 0.16; 'empty.': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'silly': 0.16; 'wrote:': 0.16; 'odd': 0.18; 'seems': 0.23; 'wrote': 0.23; 'thus': 0.24; 'header :In-Reply-To:1': 0.24; "doesn't": 0.26; 'checking': 0.27; 'community.': 0.27; 'dictionary': 0.29; 'code': 0.30; 'probably': 0.31; '"the': 0.32; 'maybe': 0.33; 'changed': 0.33; 'case,': 0.34; 'next': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'say': 0.37; 'charset:us-ascii': 0.37; 'speak': 0.38; 'test': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'your': 0.60; 'received:46': 0.63; 'decided': 0.66; 'idiomatic': 0.84; 'subject:Check': 0.95 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1440026492595:3849385184 X-MC-Ingress-Time: 1440026492595 Date: Wed, 19 Aug 2015 18:21:13 -0500 From: Tim Chase To: python-list@python.org Subject: Re: Check if dictionary empty with == {} In-Reply-To: References: X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1440027458 news.xs4all.nl 23760 [2001:888:2000:d::a6]:33094 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3480 X-Received-Body-CRC: 605267520 Xref: csiph.com comp.lang.python:95500 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