[Tutor] Simple list question

Matt Williams mw at acl.icnet.uk
Tue Oct 5 15:47:39 CEST 2004


Dear Tutor,

I got this script to permute a list off a website. It works, but when I
added the append function, it returns a list that is non-permuted.

Any ideas why?

Matt


def permute(list):
    s=[]
    len_l = len(list)
    if len_l == 1:      
        print l
        s.append(l)
        return
    for i in range (0, len_l):
        print i
        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 Tutor mailing list