This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: make r argument on itertools.combinations() optional
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: djc, mark.dickinson, rhettinger, terry.reedy
Priority: normal Keywords:

Created on 2012-05-16 14:52 by djc, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg160874 - (view) Author: Dirkjan Ochtman (djc) * (Python committer) Date: 2012-05-16 14:52
I'm not sure why this is allowed for permutations() but not combinations().
msg160882 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-05-16 16:38
Wait, what?  What results are you proposing for e.g.,

list(combinations(range(3)))

?  None of the obvious defaults for r (length of first argument?  0? 1?) look very interesting.
msg160884 - (view) Author: Dirkjan Ochtman (djc) * (Python committer) Date: 2012-05-16 16:42
[[], [0], [1], [2], [0, 1], [0, 2], [1, 2], [0, 1, 2]]

That is, all possible combinations.
msg161078 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-05-18 19:11
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)]
History
Date User Action Args
2022-04-11 14:57:30adminsetgithub: 59036
2012-05-18 19:11:25terry.reedysetstatus: open -> closed

type: enhancement
versions: + Python 3.3, - Python 3.2
nosy: + rhettinger, terry.reedy

messages: + msg161078
resolution: rejected
stage: resolved
2012-05-16 16:42:01djcsetmessages: + msg160884
2012-05-16 16:38:07mark.dickinsonsetnosy: + mark.dickinson
messages: + msg160882
2012-05-16 14:52:49djcsetversions: + Python 3.2, - Python 3.3
2012-05-16 14:52:44djcsetcomponents: + Library (Lib)
versions: + Python 3.3
2012-05-16 14:52:24djccreate