Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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