Message161078
| Author |
terry.reedy |
| Recipients |
djc, mark.dickinson, rhettinger, terry.reedy |
| Date |
2012年05月18日.19:11:25 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1337368286.34.0.953411246512.issue14831@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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 |
| 2012年05月18日 19:11:26 | terry.reedy | set | recipients:
+ terry.reedy, rhettinger, mark.dickinson, djc |
| 2012年05月18日 19:11:26 | terry.reedy | set | messageid: <1337368286.34.0.953411246512.issue14831@psf.upfronthosting.co.za> |
| 2012年05月18日 19:11:25 | terry.reedy | link | issue14831 messages |
| 2012年05月18日 19:11:25 | terry.reedy | create |
|