Python Common Operations on Lists
l.append(e)
adds the object e to the end of l
l.sort()
has the side effect of sorting the elements of l.
l.insert(i, e)
inserts the object e into l at index i
l.pop(i)
removes and returns the item at index i. Default value for i is -1.
del l[i]
removes element with index i. Raises IndexError if i is out of range.
range(stop)
returns a list of integers starting a 0 and increasing by 1 up to, but not including stop. Examples: range(6) returns [0, 1, 2, 3, 4, 5] range(0) returns [] range(3) returns [0, 1, 2]
range(start, stop, step)
returns a list starting at start and going up to but not including stop. Default value for step is 1. All inputs must be integers. Examples: range(1, 5) returns [1, 2, 3, 4] range(0, 10, 3) returns [0, 3, 6, 9] range(1, 0) returns []
l.index(e)
returns the index of the first occurrence of e in l