[issue5048] Extending itertools.combinations

2009-01-27 Thread Raymond Hettinger
Raymond Hettinger added the comment: Correction to earlier statement. It should have read: Guido disallowed returning a len method on iterators. He expected bool(it) to be always be True. ___ Python tracker _

[issue5048] Extending itertools.combinations

2009-01-27 Thread Mark Dickinson
Mark Dickinson added the comment: I only just noticed the DeprecationWarning that's already happening for float inputs in 2.7. (And float inputs already raise TypeError in 3.1.) So I agree that it's probably not worth it. ___ Python tracker

[issue5048] Extending itertools.combinations

2009-01-27 Thread Raymond Hettinger
Raymond Hettinger added the comment: Glad you like it. Will meditate for a bit on the floating point input. My first thought is that it isn't worth going through the __index__ dance to preclude inputs that look odd. ___ Python tracker

[issue5048] Extending itertools.combinations

2009-01-27 Thread Mark Dickinson
Mark Dickinson added the comment: combinations_with_replacement addition looks good. Thank you. I wonder whether the second argument should be constrained to be an integer? I find the following a little surprising: >>> list(combinations_with_replacement(range(5), -0.3)) [()] (same behaviour

[issue5048] Extending itertools.combinations

2009-01-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: FWIW, I added combinations_with_replacement() in r69001 and r69004 . ___ Python tracker ___ ___ Python-bug

[issue5048] Extending itertools.combinations

2009-01-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: Am rejecting the OP's request for the reasons cited. Also rejecting the request for a __len__ method on permutations. Ezio or Mark, please open another feature request for combinations_with_replacement() and assign to me. Will likely accept this one and pu

[issue5048] Extending itertools.combinations

2009-01-25 Thread Mark Dickinson
Mark Dickinson added the comment: So there is. Apologies---I'll try to read more carefully next time. ___ Python tracker ___ ___ Python-bugs-l

[issue5048] Extending itertools.combinations

2009-01-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: There is already a powerset() recipe in the docs. It was contributed by Eric Raymond. ___ Python tracker ___

[issue5048] Extending itertools.combinations

2009-01-25 Thread Mark Dickinson
Mark Dickinson added the comment: > that dropping the length argument will make the function iterate over > *all* combinations, Now *this* sounds more useful to me: an itertool that generates *all* subsets of a list. It's quite easy to do with existing itertools, though, either by looping

[issue5048] Extending itertools.combinations

2009-01-25 Thread Konrad
Konrad added the comment: I'm afraid I don't have any real-world use cases. Originally, I assumed that dropping the length argument will make the function iterate over *all* combinations, which would enable me to write somehow twisted, one- liner for _inefficiently_ solving knapsack problem.

[issue5048] Extending itertools.combinations

2009-01-25 Thread Mark Dickinson
Mark Dickinson added the comment: I've seen requests for combinations with replacement come up on c.l.p. a few times in the past, though it's never been clear whether there was a real need or whether the interest was driven by homework or curiosity. -1 for sequences in the second argument of

[issue5048] Extending itertools.combinations

2009-01-24 Thread Raymond Hettinger
Raymond Hettinger added the comment: Guido disallowed returning a len method on iterators. He expected bool(it) to be False. The recipes section of the itertools docs has code for combinations_with_replacement(). It was not included originally because it was unclear whether there was actually

[issue5048] Extending itertools.combinations

2009-01-24 Thread Ezio Melotti
Ezio Melotti added the comment: It would also be nice to have a __len__ method on both permutations and combinations. len(permutations(sequence)) could return the number of permutations using the formulas (e.g. n! for permutations) without generating all the possible permutations (as opposed to

[issue5048] Extending itertools.combinations

2009-01-24 Thread Raymond Hettinger
Raymond Hettinger added the comment: Do you have compelling use cases? Is it worth what it takes to preserve the relation with permuations() and product() and the lexicographic orderings? Do we care the length of the output is no longer predictable by a simple n! / r! / (n-r)! ? Do we care t

[issue5048] Extending itertools.combinations

2009-01-24 Thread Konrad
New submission from Konrad : The function itertools.combinations might 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 co