Write a function biggestAndRest that accepts one argument---a list containing integers. biggestAndRest should then return a tuple with two items: (1) the largest integer in the original list and (2) a nested tuple containing the rest of the items in the original list. For example, biggestAndRest([3,1,4,2]) should return (4, (3,2,1))

Respuesta :

Open your python console and execute the following .py code.

Code:

def biggestAndRest(lis):

   mxE = max(lis)

   maxIdx = lis.index(mxE)

   l2 = lis.copy()

   l2.pop(maxIdx)

   return mxE,tuple(l2)

r = biggestAndRest([3,1,4,2])

print(r)

Output

(4, (3, 1, 2))

Discussion

From [3,1,4,2] it became (4, (3, 1, 2))

following the principle of the function biggest and rest