As Kevin mentions in the comments, your algorithm may not be correct, but in any case, your code is not optimized.
When using very large lists, generators are usually used, there is a well-known, excellent Stackoverflow answer explaining the concepts of yield and generator - What does the do keyword do in output in Python?
The problem is that your pairs = combinations(anums, 2) does not generate a generator , but generates a large object that consumes a lot more memory.
I changed my code to this function, since you repeat the assembly only once, you can be lazy to evaluate the values:
def generator_sol(anums1, s): for comb in itertools.combinations(anums1, s): yield comb
Now instead of pairs = combinations(anums, 2) , which generates a large object. Using:
pairs = generator_sol(anums, 2)
Then instead of using lambda I would use another generator :
sums_sol = (x[0]+x[1] for x in pairs)
Another tip, you better look at xrange , which is more suitable, it does not generate a list, and xrange object which is more efficient in many cases (for example, here).
Ofiris
source share