Question: Hello, I need help to add two more functions to the following code in python. Please indent the code while posting the answer: 1. extend(
Hello, I need help to add two more functions to the following code in python. Please indent the code while posting the answer:
1. extend( otherVector ): Extends this vector by appending the entire contents of the otherVector to this vector.
2. subVector( from, to ): Creates and returns a new vector that contains a subsequence of the items in the vector between and including those indicated by the given from and to positions. Both of the from and to positions must be within the valid range.
import array as arr
class vector:
def __init__(self):
self.items=arr.array('i',[0,0])
def length(self):
return (len(self.items))
def contains(self,item):
if item in self.items:
print('found')
else:
print('not found')
def getitem(self,item):
return (self.items[item])
def setitem(self,item):
print (self.items.insert(1, item))
def append (self,item):
print(self.items.append(item))
def insert(self,item):
print (self.items.insert(4, item))
def remove(self):
return self.items.pop(1)
def indexof(self,item):
print (self.items.index(item))
v=vector()
print(v.items)
print(v.length())
print(v.contains(0))
print(v.getitem(1))
print(v.setitem(1))
print(v.items)
print(v.append(3))
print(v.items)
print(v.insert(7))
print(v.items)
print(v.remove())
print(v.items)
print(v.indexof(7))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
