mardi 11 février 2020

two for loop with restriction [1,2] and [2,1] not acceptable python

I have two for loop to select items from a list and don't want to repeat [1,2] and [2,1] similar is the case for other elements. Basically I have

for i in range(0,20):
    for j in range(0,20):
        if (i != j):
            function(list[i],list[j])

The output from [1,2] and [2,1] gives the same results and I don't want to repeat that. basically i and j are identical array. I eliminate similar elements using if loop. and I want to eliminate repeated elements.

Aucun commentaire:

Enregistrer un commentaire