Just a style question: Is there a build-in method to get the combinations under the assertion of commutative property and excluding elements paired with itself?
Assuming a and b are identical.
a
b
>>> import itertools >>> a = ["1", "2", "3"] >>> list(itertools.combinations(a,2)) [('1', '2'), ('1', '3'), ('2', '3')]