Re: [Tutor] Combination

2005-01-23 Thread Guillermo Fernandez Castellanos
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:

Re: [Tutor] Combination

2005-01-21 Thread Danny Yoo
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

Re: [Tutor] Combination

2005-01-21 Thread Danny Yoo
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

Re: [Tutor] Combination

2005-01-21 Thread Kent Johnson
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

[Tutor] Combination

2005-01-21 Thread Guillermo Fernandez Castellanos
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