Re: [Tutor] listing all combinations of elements of a list

2004-12-18 Thread Jacob S.
Am I wrong, or is that what the module sets is for? I don't remember if python 2.3 has it, but python2.4 has it available. >>> import sets >>> s = sets.Set >>> a = s([1,2,3]) >>> a Set([1, 2, 3]) >>> a.update([1,1,2,2,3,3,4,4,5,5]) >>> a Set([1, 2, 3, 4, 5]) >>> HTH, Jacob Schmidt > > def combin

Re: [Tutor] listing all combinations of elements of a list

2004-12-13 Thread Alan Gauld
> def combination(items) > list = [] > for i in range(0,len(items)): >for j in range(0,len(items)): for i in items: for j in items: Is both shorter and faster - no len() function calls. Or if you want to use indices: size = len(items) # only calculate once, it won

[Tutor] listing all combinations of elements of a list

2004-12-12 Thread Bill Kranec
Is there a module containing a function for listing the unique k-element subsets of an n-item list? I have written some code (right now I only need it for 2 element subsets): def combination(items) list = [] for i in range(0,len(items)): for j in range(0,len(items)): if j >