What's the list:
The list feels like the most python-brought data structure in Python's everyday programming. But Python's heavy list is not the same as in other languages.
Juvenile.. I wonder if you've heard that the Append method in Python is much more efficient than the Insert method? What, you don't know? Please allow Swaiiow to come slowly.
The list in other programming languages is also called a linked list, which is probably except for the last element, all elements have a pointer, this pointer only want the next element node reference.
If you want to add an element, point to the pointer in the last element that you want the app element to be inserted into? Hey, you can just point to the element you want to insert before you insert the element, and then point to the element you want to insert.
Sounds good, doesn't it?
In fact, it is also good! (This refers to a one-way list, of course)
And Python is doing this, he's storing the list structure is a whole block of memory, imagine you bought a bucket of badminton ball and then you want to take out the penultimate, think is xxxxxx
Specific to the insert operation above, in principle, each insert operation to move all the elements on the right side, and sometimes even re-establish a new memory space. To avoid this, the concept of dynamic arrays is usually used, and the core is to allocate a larger amount of memory when it is first created
It sounds like a rip-off, and think about it so that append and insert operations are very similar, but actually this kind of behavior can really reduce the cost.
My suggestion for list is that if you have a regular operation, or even a large number of requirements, then let the list bar.
Python daily-list