collection of sets

i like this post (click again to cancel)
0
i dont like this post (click again to cancel)

How to create a collection of sets and how find its subcollections of specified size

asked Sep 17 '10

sriram gravatar image sriram
11 2 2 6

updated Apr 28 '11

Kelvin Li gravatar image Kelvin Li
423 9 16

2 Answers:

i like this answer (click again to cancel)
2
i dont like this answer (click again to cancel)

Using 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'}]
link

posted Sep 18 '10

John Palmieri gravatar image John Palmieri flag of United States
2605 8 23 57
http://www.math.washingto...
i like this answer (click again to cancel)
0
i dont like this answer (click again to cancel)

Does something like this do what you're looking for?

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']

link

posted Sep 17 '10

niles gravatar image niles
3354 5 38 92
http://nilesjohnson.net/

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Tags:

Stats:

Asked: Sep 17 '10

Seen: 63 times

Last updated: Sep 18 '10

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.