Answer the question
In order to leave comments, you need to log in
Max and min values in Python?
The problem is this. There is an array of values. From it, you need to select max and min values, so that at the same time they give a value less than 1200 in total, and if this condition is met, the sum is displayed. But it is also required that those min and max that get out of the array are eliminated and the above process is repeated and repeated.
Answer the question
In order to leave comments, you need to log in
Basically it's pretty easy to do:
mass = [1000, 300, 200, 900, 100]
def f(lst, limit): [(print((a, b), a+b) if a+b < limit else None, f(list(filter(lambda x: not x in [a,b], lst)), limit)) for a,b in [(max(lst), min(lst))]] if lst else None
f(mass, 1200)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question