Hacker News new | past | comments | ask | show | jobs | submit login

It’s also pointless because Python internals have no guarantees.

Changing version or even platform can change the absolute efficiency.




(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.


Isn’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.


Check 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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: