If you want to iterate through a pair of values in a list and the order does not matter ((a,b)
is the same as (b, a)
), use itertools.combinations
instead of two for loops.
Below is an example of using for loop compared to using itertools.combinations