Py2.3: Feedback on Sets (fwd)
David Mertz
mertz at gnosis.cx
Sun Aug 17 02:55:29 EDT 2003
|mertz at gnosis.cx (David Mertz) wrote
|> Then again, power set really is a fundamental operation
|> on sets. And making users rewrite it each time is error prone.
pwmiller1 at adelphia.net (Paul Miller) wrote previously:
|How is it error prone? if P is the power set operation, and S and X
|are sets, then X in P(S) is equivalent to X is a subset of S. I don't
|think that's all that error prone.
This looks more like a definition of a method Set.ispowerset(), not one
of Set.powerset(). The actual generation of P(S) is the part I think
programmers could do wrong. I'm not saying that they might not usually
do it right... but mistakes happen.
Raymond Hettinger also wrote:
|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)])
Hmmm... I should have checked the docs first. A sample implementation
obviously helps. That said, this isn't REALLY an implementation of
powerset. It returns an iterator, not a set. Now, sure... an iterator
is a BETTER thing to get, for lots of reasons. But I'm not sure it
lives up to the function name.
Yours, David...
--
Keeping medicines from the bloodstreams of the sick; food from the bellies
of the hungry; books from the hands of the uneducated; technology from the
underdeveloped; and putting advocates of freedom in prisons. Intellectual
property is to the 21st century what the slave trade was to the 16th.
More information about the Python-list
mailing list