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
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com