Skip to content

Latest commit

 

History

History
24 lines (16 loc) · 572 Bytes

File metadata and controls

24 lines (16 loc) · 572 Bytes

String Permutation

Problem

Given a string, write a function that uses recursion to output a list of all the possible permutations of that string. For example, given s='abc' the function should return ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']

Note: If a character is repeated, treat each occurrence as distinct, for example an input of 'xxx' would return a list with 6 "versions" of 'xxx'

Code

Create your solution in the form:

def permute(s):
    pass

Example

>>> permute('abc')
['abc', 'acb', 'bac', 'bca', 'cab', 'cba']