automatic "lotjes trekken"
François Pinard
pinard at iro.umontreal.ca
Sun Aug 25 00:01:50 EDT 2002
[Tim Peters]
> [François Pinard]
> > By the way, I do not remember any standard library helper to enumerate
> > all permutations (or combinations, or arrangements) of a given list
> > (or tuple). Ideally one at a time, of course. Would this be useful?
> [...] I've likely got all the most useful algorithms coded up already
> (from permutations of n things taken k at a time, to partitions of an
> integer, in lexicographic or "Grey code" orderings).
Hello, Tim. Re-reading this old email of yours. Copy to Python list,
in case there is interest to some readers.
What do you call "partitions of an integer"?
How should I read the last "or" above? Where the expression "Grey code"
comes from? I presume there is no relation with "Gray code", because
lexicographic ordering is usually not compatible with these.
> There is a particular irritation inherent in your natural generalization
> from list to "list (or tuple)": you should really add "(or sequence)",
> including strings and user-defined sequence types. A polymorphic
> generator has to be written very carefully to work with all those types!
> It also has to be written inefficiently, since it can't assume the base
> sequence type is mutable. [...]
Indeed. I never noticed that as a difficulty before, because the
application usually knows what to expect, and could convert the result of
a combinator received as a list, back to a tuple, or string, or whatever.
As you underline, this allows the combinator routine to be written more
efficiently, indeed.
> Let's make that concrete. [...] Another irritation is that the
> for/__getitem__ protocol isn't really suited to this kind of application
> [...]
I do not quote your examples here, as you published elegant solutions
based on generators since then. That irritation is gone by now! :-)
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list