Hello I need help writing a python code. In this code, we will making a list. As
ID: 3563002 • Letter: H
Question
Hello I need help writing a python code. In this code, we will making a list. Assume, we are given a list of items, and we need to write a new function called reverse. This function creates another list in which the sequence of all the items is reversed. Here is the process we will use: - First, using just a paper and pencil, we will figure out how to do this. - Next, we will capture this algorithm, from step 1, in psuedocode. Lastly, we will write the code, and execute it. Make sure the code is well annotated. - The output should be the two lists and the big-O complexity of your code. Note: Python lists have a built in method called reverse - we will not use this method - instead we are defining our own method. If you can help me write this code I will reward points .
Thank You.
Explanation / Answer
mylist = [1,2,3,4,5]
def reverse(orig_list):
data_list = orig_list[:]
length = len(data_list)
for i in xrange(0, length/2):
tmp = data_list[length-i-1]
data_list[length-i-1] = data_list[i]
data_list[i] = tmp
return data_list
for item in reverse(mylist):
print item
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.