/ Published in: Python

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def swap(string, first, second, begin, end): string[begin] = second string[end] = first def permutate(string, begin = 0): end = len(string) -1 srange = end - begin if srange == 1: print string else: for i in range(0, srange): swap(string, string[begin], string[begin+i], begin, begin+i) permutate(string, begin+1) swap(string, string[begin], string[begin+i], begin, begin+i)
Comments
