Method | Description |
---|---|
Nonmutating methods | 聽 |
L.count(x) | Returns the number of items of L that are equal to x. |
L.index(x) | Returns the index of the first occurrence of an item in L that is equal to x, or raises an exception if L has no such item. |
Mutating methods | 聽 |
L.append(x) | Appends item x to the end of L ; e.g., L[len(L):]=[x]. |
L.extend(s) | Appends all the items of iterable s to the end of L; e.g., L[len(L):]=s. |
L.insert(i, x) | Inserts item x in L before the item at index i, moving following items of L (if any) "rightward" to make space (increases len(L) by one, does not replace any item, does not raise exceptions: acts just like L[i:i]=[x]). |
L.remove(x) | Removes from L the first occurrence of an item in L that is equal to x, or raises an exception if L has no such item. |
L.pop([i]) | Returns the value of the item at index i and removes it from L; if i is omitted, removes and returns the last item; raises an exception if L is empty or i is an invalid index in L. |
L.reverse( ) | Reverses, in place, the items of L. |
L.sort([f]) (2.3) | Sorts, in place, the items of L, comparing items pairwise via function f; if f is omitted, comparison is via the built-in function cmp. For more details, see "Sorting a list" on page 57. |
L.sort(cmp=cmp, key=None, reverse=False)(2.4) | Sorts, in-place, the items of L, comparing items pairwise via the function passed as cmp (by default, the built-in function cmp). When argument key is not None, what gets compared for each item x is key(x), not x itself. For more details, see "Sorting a list" on page 57. |
Method | Description |
---|---|
Nonmutating methods | 聽 |
D.copy( ) | Returns a shallow copy of the dictionary (a copy whose items are the same objects as D's, not copies thereof) |
D.has_key(k) | Returns TRue if k is a key in D; otherwise, returns False, just like kinD |
D.items( ) | Returns a new list with all items (key/value pairs) in D |
D.keys( ) | Returns a new list with all keys in D |
D.values( ) | Returns a new list with all values in D |
D.iteritems( ) | Returns an iterator on all items (key/value pairs) in D |
D.iterkeys( ) | Returns an iterator on all keys in D |
D.itervalues( ) | Returns an iterator on all values in D |
D.get(k[,x]) | Returns D[k] if k is a key in D; otherwise, returns x (or None, if x is not given) |
Mutating methods | 聽 |
D.clear( ) | Removes all items from D, leaving D empty |
D.update(D1) | For each k in D1, sets D[k] equal to D1[k] |
D.setdefault(k[,x]) | Returns D[k] if k is a key in D; otherwise, sets D[k] equal to x and returns x |
D.pop(k[,x]) | Removes and returns D[k] if k is a key in D; otherwise, returns x (or raises an exception if x is not given) |
D.popitem( ) | Removes and returns an arbitrary item (key/value pair) |