Question: Python code using for loop and += and *. Write a function extend(L, n) to return a new list where each item of l will

Python code using for loop and += and *.

Python code using for loop and += and *. Write a function

Write a function extend(L, n) to return a new list where each item of l will be repeated n times! For example, extend ([1, 2, 3], 2) should return [1, 1, 2, 2, 3, 3] . Use the docstring "Returns a new list where each item of L is repeated n times""" Do not change the main program. Expected output: (1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5] Hint: Try to do this with a single for loop, using the list operations += and * Give me a hint Code history 1 def extend(L, n): 2 3 4 # Main program (do not change): 5 nums = [1, 2, 3, 4, 5] 6 print(extend(nums, 3))

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!