-
Notifications
You must be signed in to change notification settings - Fork 311
distinct_permutations with incomparable items #832
Copy link
Copy link
Closed
Labels
pr-welcomeWe are open to PRs that fix this issue - leave a note if you're working on it!We are open to PRs that fix this issue - leave a note if you're working on it!
Description
Because distinct_permutations uses sorted and < it is not possible to input incomparable items.
This is unexpected since the documentation claims that distinct_permutations is equivalent to set(permutations(iterable).
Example:
>>> set(itertools.permutations(["+","+",0,1]))
{('+', '+', 0, 1),
('+', '+', 1, 0),
('+', 0, '+', 1),
('+', 0, 1, '+'),
('+', 1, '+', 0),
('+', 1, 0, '+'),
(0, '+', '+', 1),
(0, '+', 1, '+'),
(0, 1, '+', '+'),
(1, '+', '+', 0),
(1, '+', 0, '+'),
(1, 0, '+', '+')}
>>> more_itertools.distinct_permutations(["+","+",0,1])
... more_itertools/more.py:742, in distinct_permutations(iterable, r)
--> 742 items = sorted(iterable)
TypeError: '<' not supported between instances of 'int' and 'str'
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
pr-welcomeWe are open to PRs that fix this issue - leave a note if you're working on it!We are open to PRs that fix this issue - leave a note if you're working on it!