Easy List question

Matt Williams matt at mwilliams.org
Tue Oct 5 07:39:49 EDT 2004


Dear list,

Can anyone explain why the append method here returns an 'unpermuted'
list (and how to solve it_?

I'm stuck?


s=[]
def permute(list):
    len_l = len(list)
    if len_l == 1:      
        print l
        s.append(l)
    for i in range (0, len_l):
        permute(list[1:])
        # now change position of first element with next (rotate will
do it?)
        list.append(list.pop(0))
        # reflect this change in the main list
        l[len(l) - len_l:] = list
		
		

l=["a","b","c"]

permute(l)



More information about the Python-list mailing list