python 3
We would like to add cursor-based APIs to the array-backed listAPI. To this end, we are including a cursor attribute, and tworelated methods. cursor_set will set the cursor to its argumentindex, and cursor_insert will insert its argument value into thelist at the current cursor position and advance the cursor by1.
E.g, given an array-backed list l that contains the values [0,1, 2, 3, 4, 5, 6, 7, 8, 9], running the following code
l.cursor_set(5) l.cursor_insert('a') l.cursor_insert('b') l.cursor_insert('c')
will result in the updated list [0, 1, 2, 3, 4, 'a', 'b', 'c',5, 6, 7, 8, 9]
When the cursor is set to the length of the list, cursor_insertshould behave like append.
Programming rules:
- You should only add code to the cursor_insert method; the restof ArrayList is provided for reference and testing purposes only.cursor_set is already provided.
- You must adhere to the same rules when using the built-inPython list as you did in the ArrayList lab.
- Assume that cursor is set to a value between 0 and the lengthof the list (inclusive) when cursor_insert is called.
- You may not use any other data structures (this includes thebuilt-in Python list).
class ArrayList:
def __init__(self):
self.data = []
self.cursor = 0
 Â
def append(self, val):
self.data.append(None)
self.data[len(self.data)-1] = val
 Â
def cursor_set(self, idx):
self.cursor = idx
 Â
def cursor_insert(self, val):
# YOUR CODE HERE