Pulling all n-sized combinations from a list

Paul Rubin http
Wed Feb 8 16:26:45 EST 2006


"Swroteb" <swrittenb at gmail.com> writes:
> Atrocious and slow, I'm sure, but is there a better way?  I can't
> simply create a list with the combinations I want, since it won't fit
> into memory.  And I'm sure I can do it using a standard paradigm using
> five indexed for loops (ie, for i = 1, for j = i+1, for k = j+1, etc.).
>  But is there a really nice way to handle this in Python?

Is this a homework problem?  Hint: 1) use recursion; 2) use generators.



More information about the Python-list mailing list