Python Permutation Program Flow help
Posted
by dsaccount1
on Stack Overflow
See other posts from Stack Overflow
or by dsaccount1
Published on 2010-03-26T20:32:00Z
Indexed on
2010/03/26
20:33 UTC
Read the original article
Hit count: 492
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))
© Stack Overflow or respective owner