On Thu, 20 Aug 2015 11:54 pm, Skip Montanaro wrote:
On Wed, Aug 19, 2015 at 10:16 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
So maybe it's a micro-optimization?
Note, however, that the original post compared mydict == {} with not
mydict. In that case, it's
On Thu, Aug 20, 2015 at 12:44 PM, Steven D'Aprano
mailto:st...@pearwood.info wrote:
Testing for any Falsey value and an empty dict are not the same,
naturally they will perform differently.
Sure, but the OP's original note explicitly said he had a dict and
asked how to test if it was empty. He
On Wed, Aug 19, 2015 at 10:16 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
So maybe it's a micro-optimization?
Note, however, that the original post compared mydict == {} with not
mydict. In that case, it's decidedly not an optimization:
firefly% python2.7 -m timeit -s
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
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,
On Wed, Aug 19, 2015 at 6:33 PM, MRAB pyt...@mrabarnett.plus.com wrote:
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)?
Sure, that's a possibility. I would argue that mydict == {} is also
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
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
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.
Skip
--
On Thursday 20 August 2015 08: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
10 matches
Mail list logo