def __contains__(self, s): """ TESTS:: sage: S = Subsets([1,2,2,3], submultiset=True) sage: [] in S True sage: [1, 2, 2] in S True sage: all(i in S for i in S) True sage: [1, 2, 2, 2] in S False sage: [1, 3, 2, 2] in S True sage: [4] in S False """ return sorted(s) in subword.Subwords(self._s)
def __iter__(self): """ Iterates through the subsets of s. EXAMPLES:: sage: [sub for sub in Subsets(Set([1,2,3]))] [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] sage: [sub for sub in Subsets(3)] [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] sage: [sub for sub in Subsets([1,2,3,3])] [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] """ lset = __builtin__.list(self.s) #We use the iterator for the subwords of range(len(self.s)) ind_set = lambda index_list: Set([lset[i] for i in index_list]) it = itertools.imap(ind_set, subword.Subwords(range(len(lset)))) for sub in it: yield sub