“This is the first day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021”
An array ofarray
Array is more efficient than list if you need a list that contains only numbers, because arrays don’t store numeric objects (like float) behind them, but rather machine translations of numbers, called byte representations. This is just like arrays in C.
Arrays support all operations related to mutable sequences, including.pop,.insert, and.extend. In addition, arrays provide faster ways to read and store files from files, such as.frombytes and.tofile.
Array. The first argument to array specifies the data type of the array element. Python will not allow you to store data in an array other than the specified type.
The queuedeque
The Collections. deque class (two-way queue) is a thread-safe data type that can quickly add or remove elements from both ends (append and Popleft are atomic operations).
A deque is also a good choice if you want to have a data type to hold “the most recently used elements.” This is because when creating a new two-way queue, you can specify the size of the queue, and if the queue is full, you can remove the expired elements from the reverse end and add new elements at the end.
Methods to compare
methods | The list of | tuples | An array of | The bidirectional queue | instructions |
---|---|---|---|---|---|
s__add__(s2) |
There are | There are | There are | s + s2 , joining together |
|
s__iadd__(s2) |
There are | There are | There are | s += s2 , local splicing |
|
s.append(e) |
There are | There are | There are | Add a new element to the tail | |
s.appendleft(e) |
There are | Add a new element to the tail | |||
s.clear() |
There are | There are | Delete all elements | ||
s.__contains__(e) |
There are | There are | There are | s Does it includee |
|
s.copy() |
There are | A shallow copy | |||
s.__copy__() |
There are | There are | rightcopy.copy The support of |
||
s.__deepcopy__() |
There are | rightcopy.deepcopy The support of |
|||
s.count(e) |
There are | There are | There are | There are | e 在 s Frequency of occurrence in |
s.__delitem__(p) |
There are | There are | There are | Delete thep The elements of the |
|
s.extend(it) |
There are | There are | There are | Put the iterableit Appended to thes The tail |
|
s.extendleft(it) |
There are | Put the iterableit Appended to thes The head |
|||
s.__getitem__(p) |
There are | There are | There are | There are | To get inp The elements of the |
s.__getnewargs__() |
There are | inpickle Support for more optimized serialization in |
|||
s.index(e) |
There are | There are | There are | finds 中 e The location of the first appearance |
|
s.insert(p, e) |
There are | There are | In the positionp Insert elements beforee |
||
s.__iter__() |
There are | There are | There are | There are | To obtains The iterator |
s.__len__() |
There are | There are | There are | There are | len(s) Number of elements |
s.__mul__(n) |
There are | There are | There are | s * n , repeated splicing |
|
s.__imul__(n) |
There are | There are | s *= n And local repeated splicing |
||
s.__rmul__(n) |
There are | There are | There are | n * s , reverse stitching |
|
s.pop([p]) |
There are | There are | Yes (no parameter) | Delete last/locatedp Element and return its value |
|
s.popleft() |
There are | Removes the uppermost element and returns its value | |||
s.remove(e) |
There are | There are | There are | deletes For the first timee |
|
s.reverse() |
There are | There are | There are | On the reverse | |
s.__reversed__() |
There are | There are | There are | Returns an inverse-order iterator | |
s.rotate(n) |
There are | There are | then Ten elements are moved from one end of the queue to the other |
||
s.__setitem__(p, e) |
There are | There are | There are | The position ofp Replace it with elementse |
|
s.sort([key], [reverse]) |
There are | The sorting | |||
s.byteswap |
There are | Reverses the byte sequence of each element in the array | |||
s.frombytes(b) |
There are | Read the byte sequence compressed into machine values and add it to the tail | |||
s.fromfile(f,n) |
There are | Binary filesf Contains machine values read out and added to the tail, at mostn 项 |
|||
s.fromlist(l) |
There are | Add the elements in the list to the end if any of them causeTypeError Exception, then all additions are cancelled |
|||
s.tobytes() |
There are | Use the machine values of all elementsbytes Object |
|||
s.tofile(f) |
There are | Writes all elements to a file as machine values | |||
s.tolist() |
There are | Convert an array to a list of elements of type number objects | |||
s.typecode |
There are | Returns a one-character string representing the type of array elements in C |