Question
I am honestly lost on how to even begin to write code for this function based on the specification. They have a clue to use
I am honestly lost on how to even begin to write code for this function based on the specification. They have a clue to use list.insert() but based on some of the examples how would you know what number needs to be replaced if the list can change? Here are some of my thoughts: can we save each number and use indexing then use insert?
Below is the function with specifications:
def rotate(alist): """ Rotates the contents of alist one element to the right. Rotating a list to the right pushes all elements to the right, and makes the previously last element the new first element. Examples: If a = [0,2,3,4], rotate(a) makes a = [4,0,2,3] if a = [0,1,3,5], rotate(a) makes a= [5,0,1,3] if a = [0,1,3,5], rotate(a) makes a= [1,3,5,0] if a = [0,1,3,5], rotate(a) makes a= [0,1,3,5] If a = [1], rotate(a) makes a = [1] Parameter a: The list to rotate Precondition: a non-empty list """ # Hint: Read the method description for insert
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