Iterate Over Array Twice (cartesian Product) But Consider Only Half The Elements
I am trying to iterate over an array twice to have pairs of elements (e_i,e_j) but I only want the elements such that i < j. Basically, what I want would look like this is C-lik
Solution 1:
Just use itertools.combinations(my_list, 2)
.
Solution 2:
Can't you just use the range
function and go with:
vect = [...]
for i in range(0, len(vect)):
for j in range(i+1, len(vect)):
do_something()
Post a Comment for "Iterate Over Array Twice (cartesian Product) But Consider Only Half The Elements"