Check if dictionary empty with == {}
Skip Montanaro
skip.montanaro at gmail.com
Thu Aug 20 09:54:53 EDT 2015
On Wed, Aug 19, 2015 at 10:16 PM, Steven D'Aprano <
steve+comp.lang.python at 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 "mydict = {1:2}" "if mydict == {}: pass"
10000000 loops, best of 3: 0.0508 usec per loop
firefly% python2.7 -m timeit -s "mydict = {1:2}" "if not mydict: pass"
10000000 loops, best of 3: 0.0246 usec per loop
Skip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150820/5904c0ea/attachment.html>
More information about the Python-list
mailing list