ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 18 Sep 2010 06:56:39 -0500collection of setshttp://ask.sagemath.org/question/7695/collection-of-sets/How to create a collection of sets and how find its subcollections of specified sizeFri, 17 Sep 2010 01:38:04 -0500http://ask.sagemath.org/question/7695/collection-of-sets/Answer by John Palmieri for <p>How to create a collection of sets and how find its subcollections of specified size</p>
http://ask.sagemath.org/question/7695/collection-of-sets/?answer=11669#post-id-11669Using Sage code:
sage: X = Set([1, 3, "two"]) # note capital S
sage: X.subsets()
Subsets of {1, 3, 'two'}
sage: X.subsets(size=2)
Subsets of {1, 3, 'two'} of size 2
sage: X.subsets(size=2).list()
[{1, 3}, {1, 'two'}, {3, 'two'}]
Sat, 18 Sep 2010 06:56:39 -0500http://ask.sagemath.org/question/7695/collection-of-sets/?answer=11669#post-id-11669Answer by niles for <p>How to create a collection of sets and how find its subcollections of specified size</p>
http://ask.sagemath.org/question/7695/collection-of-sets/?answer=11660#post-id-11660Does something like this do what you're looking for?
<pre>
sage: s = set([1,3,"two"]) # make a set from a list of items
sage: t = list(subsets(s)); t # this is the list of all subsets of s
[[], [1], [3], [1, 3], ['two'], [1, 'two'], [3, 'two'], [1, 3, 'two']]
sage: for x in subsets(s): # subsets(s) is an iterator, so you can loop through it
....: if len(x) == 2: # and extract items of a specified length
....: print x
....:
[1, 3]
[1, 'two']
[3, 'two']
</pre>Fri, 17 Sep 2010 01:49:20 -0500http://ask.sagemath.org/question/7695/collection-of-sets/?answer=11660#post-id-11660