Answer the question
In order to leave comments, you need to log in
How to take into account the totality of the sums of all elements of the list?
There is a set of variables ae. Provided that the sum of any two elements from the list is less than the specified value, the operation is performed. How to write a check for these sums without resorting to a boring type enumeration:
if a + b < x or \
a + c < x or \:
print('...')
Answer the question
In order to leave comments, you need to log in
Are you out of your mind, are you? The whole test is something - choose the two largest variables, add and compare.
What's up?..
from itertools import combinations
values_list = [1, 2, 3]
x = 4
if any(map(lambda v: v < x, map(sum, combinations(values_list, 2)))):
print('...')
a = 1
b = 5
c = 9
x = 15
mxmGR = 0
mxmJR = 0
lst = [a, b, c]
mxm = max(lst)
mxmQnt = lst.count(mxm)
for i in lst:
if mxmQnt >= 2:
mxmGR, mxmJR = mxm, mxm
else:
mxmGR = mxm
if mxmJR < i < mxmGR:
mxmJR = i
if mxmGR + mxmJR < x:
print('...')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question