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.
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:30 | admin | set | github: 59036 |
| 2012年05月18日 19:11:25 | terry.reedy | set | status: 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:01 | djc | set | messages: + msg160884 |
| 2012年05月16日 16:38:07 | mark.dickinson | set | nosy:
+ mark.dickinson messages: + msg160882 |
| 2012年05月16日 14:52:49 | djc | set | versions: + Python 3.2, - Python 3.3 |
| 2012年05月16日 14:52:44 | djc | set | components:
+ Library (Lib) versions: + Python 3.3 |
| 2012年05月16日 14:52:24 | djc | create | |