3 ms·
IIRC lists and tuples are implemented nearly identically in CPython. So you won't find much difference here. Because Python is so dynamic, you can't make list
by colanderman 10y ago
IIRC lists and tuples are implemented nearly identically in CPython. So you won't find much difference here.
Because Python is so dynamic, you can't make lists or tuples much better. However, in a static language (like Java or OCaml), you can greatly shrink the size of "cultural" lists by hoisting the (identical) run-time type info out of the elements and into the container. (OCaml does this with floats.) And "cultural" tuples typically can use much simpler implementations, since their sizes are fixed and known at compile time. (C structs are often optimized away entirely in optimized assembly.)
- ratsbane 10y agoI'm really surprised by these numbers. There isn't really any speed advantage or significant storage advantage to using tuples over lists. That really cuts down on the rationale for using tuples over lists, except for the "cultural difference" as discussed (and the ability to use lists as dictionary keys, which isn't something I think I've ever wanted to do)