215k views
4 votes
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))

User LachlanG
by
5.2k points

1 Answer

6 votes

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

User Gregory Marton
by
4.9k points