[issue14831] make r argument on itertools.combinations() optional
Terry J. Reedy
report at bugs.python.org
Fri May 18 21:11:26 CEST 2012
Terry J. Reedy <tjreedy at udel.edu> added the comment:
permutations(i,r) has an obvious default length, len(i).
For combinations(i,r), r = len(i), the return is i itself. Uninteresting.
You are asking for something else, that combinations(i) be powerset(i), which is a different function. Powerset can be built from chain and combinations. Raymond has rejected adding powerset, which is given in the doc in 9.1.2. Itertools Recipes. In the python-ideas 'Haskell envy' thread (about combinations/powerset), that started April 22, 2012, he said:
"The whole purpose of the itertools recipes are to teach how
the itertools can be readily combined to build new tools."
from itertools import chain, combinations
def powerset(iterable):
pool = tuple(iterable)
n = len(pool)
return chain.from_iterable(combinations(pool, i) for i in range(n+1))
print(list(powerset(range(3))))
#
[(), (0,), (1,), (2,), (0, 1), (0, 2), (1, 2), (0, 1, 2)]
----------
nosy: +rhettinger, terry.reedy
resolution: -> rejected
stage: -> committed/rejected
status: open -> closed
type: -> enhancement
versions: +Python 3.3 -Python 3.2
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14831>
_______________________________________
More information about the Python-bugs-list
mailing list