Skip to content

Instantly share code, notes, and snippets.

Created September 26, 2012 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3786286 to your computer and use it in GitHub Desktop.
Save anonymous/3786286 to your computer and use it in GitHub Desktop.
def permute(s):
if len(s) == 1:
return s
else:
index = len(s) - 1
new_str = permute(s[0:index])
new_list = new_str.split(',')
res_str=''
for string in new_list:
for j in range(len(string)+1):
res_str += string[0:j] + s[index] +string[j:] +","
return res_str.rstrip(',')
l = permute('123').split(',')
for i in l:
print i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment