Ask Your Question

Revision history [back]

You may use a while loop instead. It is never sane to modify the list you iterate on inside a for loop.

i = 0
while i < len(L):
    x = L[i]
    for l in srange(N):
        if not (l in L) and M[x,l] != 0:   
            L = np.append(L,l)

Comment: the test "l in L" might be expensive (if the answer is False then you have to look through the whole list).