|
|
|
|
|
by eddie_31003
3408 days ago
|
|
What's nice about Python is it so easy to get up and running. Plus its syntax is very expressive. If you're a Computer Science student, like you actually want to learn about data structures and computer organization, then you'll definitely want to study C++. Even as a secondary language to Python. However, you can start with Python to get any idea of what it means to be a programmer. |
|
For instance you have your standard list, which IIRC is implemented as a dynamically allocated array of pointers to Python objects. This gives very fast append and pop operations on it's right side, making it a wonderful stack. However it's interface specifically lacks a dedicated prepend/appendleft operation, because appending to the left of the array involves shifting the entire structure over one place in memory. This is a very slow operation, because it must copy the entire structure to simply insert a single element. Python get's away with append on the right, by allocating a bit of extra "padding" memory on the right side, to avoid having to copy the structure. For the situation where you want to append to either side, Python offers `collections.deque`. This structure is implemented with a linked list of pointers, IIRC. Which gives very fast append operations from either side, because adding a new element only involves "hooking" the new element to the preferred side, kind of like a chain.
However for understanding how these structures are implemented C based languages are the way to go.