Py2.3: Feedback on Sets (fwd)

David Mertz mertz at
Sun Aug 17 21:48:33 CEST 2003

|> Raymond Hettinger:
|> |def powerset(iterable): ...

|David Mertz wrote:
|> Hmmm...  I should have checked the docs first.  A sample implementation
|> obviously helps.  That said, this isn't REALLY an implementation of
|> powerset.

Alex Martelli <aleaxit at> wrote previously:
|def therealpowerset(iterable):
|    return Set(powerset(iterable))

Sure.  But naming the first thing 'subsetsof()' (or 'ipowerset()' to
match some of the new itertools functions) and the second just
'powerset()' seems better to me.  Or maybe the second should be named:

However, my point above is that fewer users will lookup a sample
implementation than would use a module function.  And somewhere in that
difference, some of them will do something wrong.

|IMHO, one 'real' issue with this function is that it behaves strangely
|(to me) when iterable has duplicated elements
| data = list(iterable) -->  data = Set(iterable)

Yeah :-).  Which points out that I should have actually READ Raymond's
function, rather than just cut-and-paste it.  This seems to point out
that even the Python developers are able to make mistakes in
implementing powerset().  Which again suggests a module function
(implemented correctly) is worth having.

Yours, David...

    _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/
   _/_/    ~~~~~~~~~~~~~~~~~~~~[mertz at]~~~~~~~~~~~~~~~~~~~~~  _/_/
  _/_/  The opinions expressed here must be those of my employer...   _/_/
 _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them!  _/_/

More information about the Python-list mailing list