4 ms·
(I generally agree that everyone should almost always choose the more readable version) In this case the speed difference will likely always be there, since `d
by H8crilA 3y ago
(I generally agree that everyone should almost always choose the more readable version)
In this case the speed difference will likely always be there, since `dict()` can be overriden (monkey-patched) - hence the interpreter needs to resolve it at runtime.
- pyuser583 3y agoIsn’t some logic necessary to determine if you’re dealing with a dictionary or set? Or dictionary/set comprehension? You could probably override it using Python’s extension system. Forgive me, I know Python very well, but not C/C++. I’ve learned to make no assumptions.
- H8crilA 3y agoCheck out the Python bytecode in the article, and remember that bytecode is only generated once from the text of the program (but executed many times). "{}" is translated into a simple "make a dict" instruction.