Question: Now write a function cycle(input_list) that performs a cycling of the elements of a list as before, but this time returns the result as a

Now write a function cycle(input_list) that performs a cycling of the elements of a list as before, but this time returns the result as a new object and does not mutate the input argument. For example:

>>> a_list = [1, 2, 4, 5, 'd'] 
>>> cycle(a_list) 
[2, 4, 5, 'd', 1] 
>>> a_list 
[1, 2, 4, 5, 'd'] 
>>> cycle([4, 5]) 
[5, 4] 

Hint

To create a new list object with the same values as another list you can use the copy method:

list1 = [1, 4, "3"] 
list2 = list1.copy() 
print(id(list1),id(list2)) 
print(list2) 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!