Question
Hello, I need help to add two more functions to the following code in python: 1. extend( otherVector ): Extends this vector by appending the
Hello, I need help to add two more functions to the following code in python:
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started