Py2.3: Feedback on Sets (fwd)

Raymond Hettinger vze4rx4y at verizon.net
Sun Aug 17 18:39:22 EDT 2003


[Alex Martelli]
> |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)

[David Mertz]
> 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.

It wasn't a mistake.

I do prefer Alex's improvement because it has a weaker precondition,
but the basic code and generation method was dead-on.

The real issue with adding a module function or Set method for
powerset is the lack of compelling use cases; without those, it is
simply a cute example for the docs or an ASPN recipe.

Also, if Tim were to chime-in, I think he would abstract the
problem and say that the algorithm falls in the domain of
combinatorics (for which he has written a module) and that
powersets are just a specific case of transforming a collection
of items into a collection of all possible sub-collections.


Raymond Hettinger






More information about the Python-list mailing list