Hello world, i found this code at activestate, it takes a string and prints permutations of the string.
I understand that its a recursive function but i dont really understand how it works, it'd be great if someone could walk me through the program flow, thanks a bunch!
<pre><code>
import sys
def printList(alist, blist=[]):
if not len(alist): print ''.join(blist)
for i in range(len(alist)):
blist.append(alist.pop(i))
printList(alist, blist)
alist.insert(i, blist.pop())
if name == 'main':
k='love'
if len(sys.argv)1: k = sys.argv[1]
printList(list(k))