Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95499

Re: Check if dictionary empty with == {}

Subject Re: Check if dictionary empty with == {}
References <af138426-3eb4-4b72-aa0f-45ce7fc5c292@googlegroups.com> <CANc-5Uwh0btx9xN-7taooLv108KgYnYF-SJFMiHvGzPPM0oz4A@mail.gmail.com>
From MRAB <python@mrabarnett.plus.com>
Date 2015-08-20 00:33 +0100
Newsgroups comp.lang.python
Message-ID <mailman.18.1440027240.28100.python-list@python.org> (permalink)

Show all headers | View raw


On 2015-08-20 00:15, Skip Montanaro wrote:
> Comparison against {} will be less efficient. You need to create a
> dictionary every time instead of just checking the length of your
> dictionary, which is likely stored in the header. So, it will work, but
> certainly isn't idiomatic Python.
>
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)?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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