[issue5048] Extending itertools.combinations

Konrad report at bugs.python.org
Sun Jan 25 11:57:40 CET 2009


Konrad <konryd at gmail.com> added the comment:

I'm afraid I don't have any real-world use cases. Originally, I assumed 
that dropping the length argument will make the function iterate over 
*all* combinations, which would enable me to write somehow twisted, one-
liner for _inefficiently_ solving knapsack problem.

max((comb for comb in all_combinations(zip(weights, values))
       if sum(map(itemgetter(0), comb)) < LIM), 
     key=lambda comb: sum(map(itemgetter(1), comb)))

But unfortunately, this is far from being 'compelling'.

Regarding other issues you raised: I think it would be pretty clear for 
the user, that the length of every combination might vary - that's what 
he asked for. And the length might be computed by summing the lengths 
counted using given formula, which is (for me at last) still explicit 
enough.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5048>
_______________________________________


More information about the Python-bugs-list mailing list