Question

I am using itertools in python2.7. I want to find all combinations (without repeatation). I have list of length 30 as iterable. While I save iterable object as list, it hangs or takes very long time. Can someone please help me with this..

#!usr/bin/python
import itertools
a = range(30)
list1 = []
for i in range(30):
    list1 = list(itertools.combinations(a,i))
Was it helpful?

Solution

What you're trying to do here is create a series of lists of tuples that total an extremely large number of elements - more specifically, 2**30 = 1,073,741,824 tuples, each of which will contain, on average, 15 integers. That's 16,106,127,360 (sixteen billion) integers. Even if you had enough memory to store them all, it's obviously going to take a very long time.

The chances are that you're coming at your problem from the wrong direction (see the XY problem). If you post a new question that explains the problem you're actually trying to solve, there's a chance someone may be able to help, but as it stands, your question boils down to "why does trying to do an unreasonably large amount of work take an unreasonably large amount of time?", which no-one's going to be able to help you with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top