Взгляните на itertools.combinations
def first_attempt(A=A):
for i in xrange(1,len(A)+1):
print [comb
for comb in list(itertools.combinations(A,i))
if 4.5 < sum(map(float, comb)) < 5.5
]
## -- End pasted text --
In [1861]: %timeit first_attempt
10000000 loops, best of 3: 29.4 ns per loop
Выход -
In [1890]: first_attempt(A=A)
[]
[(2, 3), (2, 2.6)]
[(0.4, 2, 3), (0.4, 2, 2.6), (0.4, 3, 1.4)]
[]
[]
[]