本例是求两个数值的和大于等于776且和是最小的的两个数。
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 13 10:49:32 2018
@author: FanXiaoLei
"""
import itertools
import sys
data=[161,184,265,462,475,476,532,550,651,973]
res=list(itertools.combinations(data,2))
mymin=sys.maxsize
xx=[None]*2
for d in res:
mysum=sum(d)
if mysum>=776 and mysum<mymin:
mymin=mysum
xx[0]=d[0]
xx[1]=d[1]
if xx[0] is None :
print('没有找到符合要求的数值')
else:
print('和大于776的最小两个数字为',xx[0],xx[1])
结果如下: