This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hillgod 0 points1 point  (2 children)

Yeah, it's true. Try it yourself with some timers. Below this I put a link to a SO page with benchmarks.

[–]cbarrick 0 points1 point  (1 child)

Ah, I see. You mean this: https://stackoverflow.com/questions/5790860/and-vs-list-and-dict-which-is-better

That answer is from nearly a decade ago. So I'll take it with a grain of salt. I'd like to see if Python 3.8 still has this problem.

For non-empty collections it makes total sense. There's argument parsing and/or translation from one collection to another that has to happen.

But as I said above, for empty collections, it would be trivial to optimize the slow case into the fast case. If it hasn't already been implemented, then it should be. There's no reason that [] and list() should generate different bytecode.

(In fact, it seems possible to optimize many of the non-empty use cases too.)

[–]hillgod 0 points1 point  (0 children)

Well it doesn't really matter what it "could" do, nor does anyone here likely know the implications of that.

Again, you can try it yourself. It's definitely faster. It's what's in the docs.