4 ms·
Python lists are dynamic arrays, not linked lists.
by proaralyst 8y ago
Python lists are dynamic arrays, not linked lists.
- umanwizard 8y agoThen why does the article incorrectly claim that Python doesn't support arrays? The whole point of my comment is that I went away from the article still not knowing whether Python has arrays, or not. I can't understand how anyone would defend an article called "X" that doesn't even properly inform you whether X exists
- deathanatos 8y agoThe article is not even wrong. That first yellow highlight is … ugh. If a programmer from another language asks for an array, I'm going to point them at the `list` class in Python. As some other sub-comments under your original post note, some uses of an array want the actual data to be contiguous. But Python `list`'s values are references to other values, not the direct values themselves. If you're familiar w/ C, it's closer to an array of pointers to objects. That matters for some niche cases. But in basic tutorial? No. And Python has some built-in types to account for some of the niche cases. Sure, that pointer is not free, and the overhead of a Python object is not free, but Python is a high level scripting language, and generally, `list` provides a random-access ordered collection, which is what most people want when they say "array", and the overhead doesn't matter for many things.
- bizmuthrocks 8y agoWhy are you being so insufferably dense? Are you always like this?
- ben509 8y agoPython's list type is implemented as a dynamic array in CPython. This is not required. An optimizing Python doing escape analysis could see a list was going to be converted to a set and swap in a set and change the method calls. Or it could see a large number of concatenations and use a linked list as an intermediate form.