M7S6 Array Methods
M7S6 Array Methods
Module 7 Subtopic 6
medium.com
At the end of this lesson, the students should be
able to:
Sample Output:
Sample Output:
• Removes all the elements from the list
Syntax: list.clear()
Sample Output:
Sample Code:
• The copy() method returns a copy of the specified list.
Syntax: list.copy()
Sample Code:
Sample Output:
Sample Output:
Add a tuple to the fruits list:
Add a tuple to the fruits list:
Sample Code:
Sample Output:
Sample Output:
• The insert() method inserts the specified value at the
specified position.
Parameters:
Syntax: list.insert(pos, elmnt)
Pos – is required. A number specifying in which
Sample Code: position to insert the value.
Sample Output:
• The pop() method removes the element at the
specified position.
Pos – Optional. A number specifying the position of
Syntax: list.pop(pos)
the element you want to remove, default value is -1,
which returns the last item.
Sample Code:
Sample Code:
Sample Output:
Sample Output:
• The remove() methods removes the first occurrence
of the element with the specified value.
Syntax: list.remove(elmnt)
Parameters:
Sample Code:
Elmnt – is required. Any type (string, number, list. Etc.)
The element you want to remove.
Sample Output:
• The reverse() method reverses the sorting order of the
elements.
Syntax: list.reverse()
Sample Output:
Sample Output:
1. Sort a list of dictionaries based on the "year" value of the dictionaries: