Common List Object action methods:
List.append (x)
Add an element to the end of the list, equivalent to A[len (a):] = [x].
List.extend (L)
Adds all the elements in a given list to another list, equivalent to A[len (a):] = L.
List.insert (i, X)
Inserts an element at the specified location. The first parameter is the index of the element that is ready to be inserted in front of it, for example, A.insert (0, X) is inserted into the entire list, and A.insert (Len (a), x) is the equivalent of A.append (x).
List.remove (x)
Deletes the first element in the list that has a value of x. If there is no such element, an error is returned.
List.pop ([i])
Deletes the element from the specified location in the linked list and returns it. If no index is specified, A.pop () returns the last element. The element is then deleted from the list. (The square brackets on both sides of the method indicate that this parameter is optional, rather than asking you to enter a pair of brackets, which you will often encounter in the Python Library Reference Manual.) )
List.index (x)
Returns the index of the element with the first value of x in the list. If there is no matching element, an error is returned.
List.count (x)
Returns the number of times X appears in the linked list.
List.sort ()
Sorts elements in a linked list in place.
List.reverse ()
In-place inverted elements in a linked list.
Cases:
Copy Code code as follows:
>>> a = [66.25, 333, 333, 1, 1234.5]
>>> Print A.count (333), A.count (66.25), A.count (' x ')
2 1 0
>>> A.insert (2,-1)
>>> A.append (333)
>>> A
[66.25, 333,-1, 333, 1, 1234.5, 333]
>>> A.index (333)
1
>>> A.remove (333)
>>> A.index (333)
2
>>> A
[66.25,-1, 333, 1, 1234.5, 333]
>>> A.reverse ()
>>> A
[333, 1234.5, 1, 333,-1, 66.25]
>>> A.sort ()
>>> A
[-1, 1, 66.25, 333, 333, 1234.5]