Got it.
import copy
def rec(list,length):
result=[]
if len(list)<=length:
return [list]
for elem in list:
temp=copy.deepcopy(list)
temp.remove(elem)
temp=rec(temp,length)
for i in temp:
On Fri, 21 Jan 2005, Danny Yoo wrote:
> > I mean:
> > if I enter (1,2,3,4,5) and I watn combinations of 3, I want to find:
> > (1,2,3) but then not (2,1,3), (3,1,2),...
> > (1,2,4)
> > (1,2,5)
> > (2,3,5)
> > (3,4,5)
>
>
> There is a clean recursive way to define this.
Hi Guillermo,
Gaaa; I s
On Fri, 21 Jan 2005, Guillermo Fernandez Castellanos wrote:
> I'm trying to take a list and find all the unique combinations of that
> list.
>
> I mean:
> if I enter (1,2,3,4,5) and I watn combinations of 3, I want to find:
> (1,2,3) but then not (2,1,3), (3,1,2),...
> (1,2,4)
> (1,2,5)
> (2,3,5
This question comes up regularly on comp.lang.python. Search the archives for 'combinations' to find
*many* discussions of how to do it. Also there are several recipes in the cookbook.
http://groups-beta.google.com/group/comp.lang.python?hl=en&lr=&ie=UTF-8&c2coff=1
http://aspn.activestate.com/ASPN
Hi,
I'm trying to take a list and find all the unique combinations of that list.
I mean:
if I enter (1,2,3,4,5) and I watn combinations of 3, I want to find:
(1,2,3) but then not (2,1,3), (3,1,2),...
(1,2,4)
(1,2,5)
(2,3,5)
(3,4,5)
The thing is, I want to do it as a generic function, where I pas