In Python 3.5 or newest release Imagine that the most of the functions that we h
ID: 3691495 • Letter: I
Question
In Python 3.5 or newest release
Imagine that the most of the functions that we have been using to process lists in Python do not exist. For the problems below you are not allowed to use any list methods (append, remove, insert, etc) or certain core Python functions specified in each problem. You may, however, use your own custom-written functions to solve these problems (i.e. if you find that your listlen() function would be useful in writing another function you are welcome to use it). Given these restrictions, write a series of functions that do the following:
7. Write a new function called "listreverse" based on the following IPO
Make sure that you DO NOT use any list methods such as "reverse" your program. Note that your original list should not change when you run this function. Here is a sample running of this program:
Explanation / Answer
def listlen(l):
ans=0
while True:
try:
a = l[ans]
ans+=1
except:
return ans
def listinverse(l):
ln = listlen(l)
a = [0]*ln
for i in range(ln):
a[ln-i-1]=l[i]
return a
b = [1,2,3,4,5,6,7,8]
a = listinverse(b)
print(b)
print(a)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.