This notebook was prepared by Donne Martin. Source and license info is on GitHub.
* None -> None * '' -> '' * 'AABC' -> ['AABC', 'AACB', 'ABAC', 'ABCA', 'ACAB', 'ACBA', 'BAAC', 'BACA', 'BCAA', 'CAAB', 'CABA', 'CBAA']
Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.
class Permutations(object):
def find_permutations(self, string):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_permutations.py
import unittest
class TestPermutations(unittest.TestCase):
def test_permutations(self):
permutations = Permutations()
self.assertEqual(permutations.find_permutations(None), None)
self.assertEqual(permutations.find_permutations(''), '')
string = 'AABC'
expected = [
'AABC', 'AACB', 'ABAC', 'ABCA',
'ACAB', 'ACBA', 'BAAC', 'BACA',
'BCAA', 'CAAB', 'CABA', 'CBAA'
]
self.assertEqual(permutations.find_permutations(string), expected)
print('Success: test_permutations')
def main():
test = TestPermutations()
test.test_permutations()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.