Skip to content

Latest commit

 

History

History

04-03 String Permutation

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

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']