In Python IDLE: How would I write a function for the problem in the attached image? >> interleaved( [-7, -2, -1], [-4, 0, 4, 8])2[-7, -4, -2, -1, 0, 4, 8]3>>> interleaved( [-4, 0, 4, 8], [-7, -2,...

In Python IDLE: How would I write a function for the problem in the attached image?interleaved<br>Write a function interleaved that accepts two sorted sequences of numbers and returns a<br>sorted sequence of all numbers obtained by interleaving the two sequences. Guidelines:<br>• each argument is a list<br>• assume that each argument is sorted in non-decreasing order (goes up or stays the same,<br>never goes down)<br>• you are not allowed to use sort or sorted (or any other form of sorting) in your solution<br>• you must interleave by iterating over the two sequences simultaneously, choosing the<br>smallest current number from each sequence.<br>Sample usage:<br>1<br>>>> interleaved( [-7, -2, -1], [-4, 0, 4, 8])<br>2<br>[-7, -4, -2, -1, 0, 4, 8]<br>3<br>>>> interleaved( [-4, 0, 4, 8], [-7, -2, -1])<br>4<br>[-7, -4, -2, -1, 0, 4, 8]<br>>>> interleaved( [-8, 4, 4, 5, 6, 6, 6, 9, 9], [-6, -2, 3, 4, 4, 5, 6, 7,<br>8])<br>[-8, -6, -2, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9]<br>7<br>>>> interleaved( [-3, -2, 0, 2, 2, 2, 3, 3, 3], [-3, -2, 2, 3])<br>8<br>[-3, -3, -2, -2, 0, 2, 2, 2, 2, 3, 3, 3, 3]<br>9.<br>>>> interleaved( [-3, -2, 2, 3], [-3, -2, 0, 2, 2, 2, 3, 3, 3])<br>10<br>[-3, -3, -2, -2, 0, 2, 2, 2, 2, 3, 3, 3, 3]<br>11<br>>>> interleaved([1,2,2],[])<br>12<br>[1, 2, 2]<br>13<br>>>> interleaved([],[1,2,2])<br>14<br>[1, 2, 2]<br>15<br>>>> interleaved ([],[])<br>16<br>[]<br>17<br>>>> interleaved( list(range(-2,12,3)), list(range (20,50,5)) )<br>18<br>[-2, 1, 4, 7, 10, 20, 25, 30, 35, 40, 45]<br>19<br>>>> interleaved( list(range (20,50,5)), list(range(-2,12,3)) )==[-2, 1, 4,<br>7, 10, 20, 25, 30, 35, 40, 45]<br>20<br>True<br>

Extracted text: interleaved Write a function interleaved that accepts two sorted sequences of numbers and returns a sorted sequence of all numbers obtained by interleaving the two sequences. Guidelines: • each argument is a list • assume that each argument is sorted in non-decreasing order (goes up or stays the same, never goes down) • you are not allowed to use sort or sorted (or any other form of sorting) in your solution • you must interleave by iterating over the two sequences simultaneously, choosing the smallest current number from each sequence. Sample usage: 1 >>> interleaved( [-7, -2, -1], [-4, 0, 4, 8]) 2 [-7, -4, -2, -1, 0, 4, 8] 3 >>> interleaved( [-4, 0, 4, 8], [-7, -2, -1]) 4 [-7, -4, -2, -1, 0, 4, 8] >>> interleaved( [-8, 4, 4, 5, 6, 6, 6, 9, 9], [-6, -2, 3, 4, 4, 5, 6, 7, 8]) [-8, -6, -2, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9] 7 >>> interleaved( [-3, -2, 0, 2, 2, 2, 3, 3, 3], [-3, -2, 2, 3]) 8 [-3, -3, -2, -2, 0, 2, 2, 2, 2, 3, 3, 3, 3] 9. >>> interleaved( [-3, -2, 2, 3], [-3, -2, 0, 2, 2, 2, 3, 3, 3]) 10 [-3, -3, -2, -2, 0, 2, 2, 2, 2, 3, 3, 3, 3] 11 >>> interleaved([1,2,2],[]) 12 [1, 2, 2] 13 >>> interleaved([],[1,2,2]) 14 [1, 2, 2] 15 >>> interleaved ([],[]) 16 [] 17 >>> interleaved( list(range(-2,12,3)), list(range (20,50,5)) ) 18 [-2, 1, 4, 7, 10, 20, 25, 30, 35, 40, 45] 19 >>> interleaved( list(range (20,50,5)), list(range(-2,12,3)) )==[-2, 1, 4, 7, 10, 20, 25, 30, 35, 40, 45] 20 True
Jun 04, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here