> Raymond Hettinger wrote: >> Since I expect students to be among the users for the comb/perm >> functions, there is some merit to keeping the API as simple as possible. >> Besides, it is not hard to use the existing tool as a primitive to get to >> the one you want: >> >> def mycombinations(iterable, r_seq): >> # mycombinations('abc', [1,2]) --> A B C AB AC BC >> iterable = list(iterable) >> return chain.from_iterable(imap(combinations, repeat(iterable), >> r_seq)) [Nick Coglan] > Perhaps a reasonable starting point would be to include this as one of > the example itertools recipes in the documentation? I would have suggested that but recipe itself is use case challenged. The OP did not mention any compelling use cases or motivations. Essentially, he just pointed-out that it is possible, not that it is desirable. I can't the of a case where I've wanted to loop over variable length subsequences. Having for-loops with tuple unpacking won't work because the combos have more than one possible size. This seems like a hypergeneralization to me. Raymond
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4