From: "Konrad Delong" <konryd at gmail.com> > I'm not sure if it's the right place to post it. If so - I'll be glad > to learn where is one. Please post a feature request on the bug tracker and assign it to me. > Anyway: > I think the function itertools.combinations would benefit from making > the 'r' (length of the combinations) argument optionally a sequence. > > With that change one could call combinations(sequence, [2, 3]) in > order to get all combinations of length 2 and 3. > In particular, one could call combinations(sequence, > range(len(sequence)) in order to get *all* combinations of given > sequence. This design is similar to the API for similar functionality in mathematica. The question is whether there are sufficient worthwhile use cases to warrant the added API complexity and algorithm complexity. The latter is a bit tricky if we want to maintain the lexicographic ordering and the notion of combinations being a subsequence of the permutations code. 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)) > PS. Didn't want to spoil the beginning of the post, but I consider it > to be a good practice to introduce oneself when posting the first > time, so: Hello, my name is Konrad, I'm an IT student and I'm > following python-dev for some time, but never posted before. Hello Konrad. Welcome to python-dev. Raymond Hettinger
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