collection of sets
How to create a collection of sets and how find its subcollections of specified size
add a comment
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']
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 14 years ago
Seen: 376 times
Last updated: Sep 18 '10