1

I have a Memory error when I use combinations with a big list of list like len 735. Any way to do a similar process but without the error?

from itertools import combinations

valores = [[5, 10.732544898986816], [9, 10.596251487731934], [11, 10.70582103729248]]
f = list(combinations(valores, 3))

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError
2

2 Answers 2

4

If your list has 735 elements, then there are (735 choose 3) = 65907695 combinations of three elements. There is probably no need to keep all of these 3-tuples in memory at the same time, so don't build a list out of them; just iterate directly.

for c in combinations(valores, 3):
    # do something with c
Sign up to request clarification or add additional context in comments.

Comments

1

You can try to prevent memory error.

comb_iter = itertools.combinations(valores,3)

for item in comb_iter:
   do_the_stuff(item)

As a result, python will keep in memory only the currently used combination, not all the combinations.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.