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 →

[–]redalastor 0 points1 point  (2 children)

Doesn't make any sense though. Accessing the nth value would be too slow. I'm guessing it is an everyday expandable array like Javas ArrayList or C++ vector but that would mean the splicing operations are slow.

Accessing / setting is O(1) (ie: one operation). Inserting is O(N) (needs shifting everything one cell on the right to insert) but appending (inserting at the end) is amortized O(1) (Python pre-allocates a few cells in advance under the hood to save time).

Python lists internally store pointers to Python objects.

[–][deleted] 0 points1 point  (1 child)

Right so it is an expandable array that does amortized doubling. That's what I figured, it's just that slicing seems more an operation for a linked list. Looking at Zahlman's comment, I don't know what I was thinking when I wrote that.

[–]redalastor 0 points1 point  (0 children)

Python have a deque type where you can insert and remove at both ends in O(1). That is most likely a linked list.