Last Updated: February 25, 2016
· wyuenho
Img 0675

Prefer {} over dict() in Python 2.7

Doug Hellman has recently done some investigations into the performance impact of using dict() instead of {} in Python 2.7 and he's concluded that dict() is 6 times more costly than {} because it does a lot more work under the hood to convert keyword arguments to a dict.


2 Responses
Add your response


It's fair to point out it only applies to CPython 2.7. My friend tells me that there's virtually no difference on 3.3 or PyPy.

over 1 year ago ·
Img 0675

@milancermak Yep, but regardless, {} is still preferred over dict() due to succinctness.

over 1 year ago ·