得a字典当中任意值相加,要最接近并大于x数值

a = {'a': 50, 'c': 89, 'b': 99, 'd': 34,"e":12,"f":45}
x = 241

得a字典当中任意值相加,要最接近并大于x数值

从而得到列表


    a = {'a': 50, 'c': 89, 'b': 99, 'd': 34, "e": 12, "f": 45}
    x = 200
    a = sorted(a.items(), key=lambda x: x[1])
    flag = True
    for item_a in a:
        for item_b in a:
            if item_a[1]+item_b[1] >= x:
                print([item_a[1], item_b[1]])
                flag = False
                break
        if not flag:
            break
    if flag:
        print("没有任意两个数相加能大于x")