29All Permutations
Hardrecursionbacktracking
Write permutations(text) that returns a sorted list of every distinct way to rearrange the characters of text.
Letters can repeat, so "aab" has only 3 distinct permutations: ["aab", "aba", "baa"].
Examples
Example 1
>>> permutations('abc') ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
Example 2
>>> permutations('aab') ['aab', 'aba', 'baa']
Good to know
- Write it yourself with recursion;
itertoolsis not needed.
Run examples checks the 2 examples above. Submit runs all 6 tests, including hidden edge cases, and marks the challenge solved.