veingrow veingrow - 1 year ago 167
Python Question

Double for loop in Python3

There is list named L.
Which contains others list: L=[A,B,C,...N]
I want to for-loop, where B is no equal A (see #2)
Something like: for B is not A in L:

for A in L: #1
for B in L: #2

How can I do that?

Answer Source

Just access the rest of the list by index:

for i in xrange(len(L)-1):
    for j in xrange(i+1, len(L)):
        #L[i] != L[j] always, and will check just one list against the others once
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download