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.
Written by Jimmy Yuen Ho Wong
Related protips
2 Responses
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
·
@milancermak Yep, but regardless, {} is still preferred over dict() due to succinctness.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Related Tags
#python
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#