[Tutor] declaring list

Logesh Pillay logesh at iafrica.com
Thu Jan 12 05:03:58 CET 2006

hello list

I asked yesterday how we can "declare" an array in python.  Thanks Brian
van den Broek and Frank Schley for your responses.

A[None] * n works for me.

To answer Brian's question, I was writing the standard backtracking
procedure to find the permutations of 1..n taken r at a time.

def permutations (n, r):
    A, Used = [None] * (r+1), [False] * (n+1)
    def choose (m):
        if m > r:
            print A[1:],
            for j in range (1, n+1):
                if not Used [j]:
                    Used [j] = True
                    A[m] = j
                    choose (m+1)
                    Used [j] = False
    choose (1)
Logesh Pillay

More information about the Tutor mailing list