A
A
ABRAM STANISLAVSKY2021-04-30 10:29:34
Python
ABRAM STANISLAVSKY, 2021-04-30 10:29:34

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

1 answer(s)
M
MinTnt, 2021-04-30
@MinTnt

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)

Because you didn't specify if both min and max are the same number, which is the case. That will be so.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question