List Methods

List function description
append(x: object): None Adds an element x to the end of the list.
count(x: object): int Returns the number of times element x appears in the list.
extend(l: list): None Appends all the elements in l to the list.
index(x: object): int Returns the index of the first occurrence of element x in the list.
insert(index: int, x: object): None Inserts an element x at a given index. Note that the first element in the list has index 0.
pop(i): object Removes the element at the given position and returns it. The parameter i is optional. If it is not specified, list.pop() removes and returns the last element in the list.
remove(x: object): None Removes the first occurrence of element x from the list.
reverse(): None Reverses the elements in the list.
sort(): None Sorts the elements in the list in ascending order.
 >>>
 list1 = [2, 3, 4, 1, 32, 4]
 >>> list1.append(19)
 >>> list1
 [2,3, 4, 1, 32, 4, 19]
 >>>  list1.count(4) # Return the count for number 4
 2
 >>> list2 = [99, 54]
 >>> list1.extend(list2)
 >>> list1
 [2,3, 4, 1, 32, 4, 19, 99, 54]
 >>> list1.index(4) # Return the index of number 4
 2
 >>> list1.insert(1, 25) # Insert 25 at position index 1
 >>> list1
 [2, 25, 3, 4, 1, 32, 4, 19, 99, 54]
 >>>

 >>> list1 = [2, 25, 3, 4, 1, 32, 4, 19, 99, 54]
 >>> list1.pop(2)
 3
 >>> list1
 [2, 25, 4, 1, 32, 4, 19, 99, 54]
 >>> list1.pop()
 54
 >>> list1
 [2, 25, 4, 1, 32, 4, 19, 99]
 >>> list1.remove(32) # Remove number 32
 >>> list1
 [2, 25, 4, 1, 4, 19, 99]
 >>> list1.reverse() # Reverse the list
 >>> list1
 [99, 19, 4, 1, 4, 25, 2]
 >>> list1.sort() # Sort the list
 >>> list1
 [1, 2, 4, 4, 19, 25, 99]
 >>>