Py2.3: Feedback on Sets (fwd)
Raymond Hettinger
vze4rx4y at verizon.net
Sat Aug 16 17:50:18 EDT 2003
[Raymond]
> > * Is there a compelling need for additional set methods like
> > Set.powerset() and Set.isdisjoint(s) or are the current
> > offerings sufficient?
[David Mertz]
> I confess that I have not used sets for anything beyond testing. I love
> the concept, but I just haven't had the need yet (especially in
> something where I want to require 2.3).
>
> The mention of Set.powerset() above is quite interesting to me. It
> feels both exciting and dangerous :-).
There would need to be compelling use cases before it would be
added to the API.
How about just adding a cut-and-paste recipe to the docs:
from sets import Set
def powerset(iterable):
data = list(iterable)
for i in xrange(2**len(data)):
yield Set([e for j,e in enumerate(data) if i&(1<<j)])
>>> list(powerset('abc'))
[Set([]), Set(['a']), Set(['b']), Set(['a', 'b']), Set(['c']), Set(['a', 'c']),
Set(['c', 'b']), Set(['a', 'c', 'b'])]
Raymond Hettinger
More information about the Python-list
mailing list