Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. Make sure that you maintain proper indentations while pasting the below code into your program, I’m also attaching the code in both text and image formats, so in case if the indentation is messed up, you can refer the image and maintain proper spacing in each and every line. Thanks
If you are satisfied with the solution, please rate the answer. If not, let me know before you rate the answer, I’ll correct anything you want.
#code
def reverse_pure(lst):
#defining an empty list
reversed=[]
#finding last index of parameter list
index=len(lst)-1
#iterating from rear to front
while index>=0:
#adding current
element to new list
reversed.append(lst[index])
index-=1 #previous
index
return reversed
#returning new list containing elements in reverse
order
def reverse_mut(lst):
#finding the length of lst list
size=len(lst)
#looping from i=0 to i=size/2
for i in
range(size//2):
#swapping elements
at index i and index size-i-i
#that is swapping ith
element from front and ith element from rear
temp=lst[i]
lst[i]=lst[size-1-i]
lst[size - 1 -
i]=temp
#end of method, now the lst will be in
reverse order.
#testing
myList=[5,12,34,0,1]
newList=reverse_pure(myList)
print(newList) # [1, 0, 34, 12, 5]
print(myList) # [5, 12, 34, 0, 1]
reverse_mut(myList)
print(myList) # [1, 0, 34, 12, 5]
#code screenshot
#output
[1, 0, 34, 12, 5]
[5, 12, 34, 0, 1]
[1, 0, 34, 12, 5]
Problem 8 In class, we discussed the difference between a pure (or effect-free) function (i.e. one...
Write a Python program that tests the function main and the functions discussed in parts a through g. Create the following lists: inStock - 2D list (row size:10, column size:4) alpha - 1D list with 20 elements. beta - 1D list with 20 elements. gamma = [11, 13, 15, 17] delta = [3, 5, 2, 6, 10, 9, 7, 11, 1, 8] a. Write the definition of the function setZero that initializes any one-dimensional list to 0 (alpha and beta)....
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...
can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...
Problem Set 2: Inheritance and Method Overriding The goal of this problem set is to apply inheritance and method overriding in order to create a hierarchy of array sorters. There exist many algorithms to sort arrays. In this problem set, we are especially interested in “in-place” sorting algorithms like Selection Sort and Insertion Sort. In-place sorting refers to an approach in which we perform the sorting steps on the underlying array rather than using extra storage. When using object-oriented design,...
Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a = [ [93, 80, 99, 72, 86, 84, 85, 41, 69, 31], [15, 37, 58, 59, 98, 40, 63, 84, 87, 15], [48, 50, 43, 68, 69, 43, 46, 83, 11, 50], [52, 49, 87, 77, 39, 21, 84, 13, 27, 82], [64, 49, 12, 42, 24, 54, 43, 69, 62, 44], [54, 90, 67, 43, 72, 17, 22, 83, 28, 68], [18, 12, 10,...
Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...
In this lab you will convert lab5.py to use object oriented programming techniques. The createList and checkList functions in lab5.py become methods of the MagicList class, and the main function of lab6.py calls methods of the MagicList class to let the user play the guessing game. A. (4pts) Use IDLE to create a lab6.py. Change the 2 comment lines at the top of lab6.py file: First line: your full name Second line: a short description of what the program...