The data structure of Python

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

1.list

The list list, equivalent to Java list. The main methods are as follows: (the copy)

list.append(x)

To add an item to the end of the list, the equivalent of a[len(a):] = [x] .

list.extend(L)

All the elements of a given list are added to another list, equivalent to a[len(a):] = L .

list.insert(i, x)

Inserts an element at the specified location. The first parameter is ready for insertion into the elements of the front of the index, for example a.insert (0, x) will be inserted into the front of the list, and a.insert (len (a), x) equivalent to a.append(x) .

list.remove(x)

Remove the first item list whose value is x. If no such element, will return an error.

list.pop([i])

Delete the elements given position in the list, and return it. If you do not specify an index, (a.pop) returns the last element. The element is deleted from the list. Methods I (on both sides of the square brackets denote that the parameter is optional, not ask you to enter the square brackets, you will often encounter such markers in the Python library reference. )

list.index(x)

Returns the first value is index x elements in the list. If no matching element will be an error return.

list.count(x)

Return the number appears in the list of X.

list.sort()

The elements in the list in sorted.

list.reverse()

In situ reverse the elements of the list,.

 

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Randolph at December 05, 2013 - 1:02 PM