ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 18 Sep 2010 02:37:18 -0500collection of setshttps://ask.sagemath.org/question/7699/collection-of-sets/How to create a collection of sets and how find its subcollections of specified size
ordered pairs for example say a collection of set {[1,2,3],[3,2,4],[1,2,4]}
subcollection of size 2
{[1,2,3],[3,2,4]}
{[3,2,4],[1,2,3]}
{[3,2,4],[1,20,4]}
{[1,20,4],[3,2,4]}
{[1,2,3],[1,2,4]}
{[1,2,4],[1,2,3]}
Is it possible to do this program below without finding all subsets
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']
Fri, 17 Sep 2010 23:00:14 -0500https://ask.sagemath.org/question/7699/collection-of-sets/Answer by niles for <p>How to create a collection of sets and how find its subcollections of specified size</p>
<p>ordered pairs for example say a collection of set {[1,2,3],[3,2,4],[1,2,4]}
subcollection of size 2
{[1,2,3],[3,2,4]}
{[3,2,4],[1,2,3]}
{[3,2,4],[1,20,4]}
{[1,20,4],[3,2,4]}
{[1,2,3],[1,2,4]}
{[1,2,4],[1,2,3]}</p>
<p>Is it possible to do this program below without finding all subsets
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']]</p>
<p>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
....: <br/>
[1, 3]
[1, 'two']
[3, 'two']</p>
https://ask.sagemath.org/question/7699/collection-of-sets/?answer=11668#post-id-11668Hi sriram,
I think this question is pretty unreadable to anyone but me; maybe it would be easier to update the [other question where you asked the same thing](http://ask.sagemath.org/question/126/collection-of-sets) (you will see an "edit" button near the bottom of the question).Sat, 18 Sep 2010 02:37:18 -0500https://ask.sagemath.org/question/7699/collection-of-sets/?answer=11668#post-id-11668