Iterating over the list of all combinations between elements of a list
06 May 2014The Issue
Did you ever had to compare all elements of a list and you had this ugly code:
We’re near the 80 character limit before even starting to write the main code.
The Solution:
Use itertools.combinations(iterable, r). It’s a function that creates tuples with length r (e.g. (x,x) for r=2, (x,x,x) for r=3 …).
Blessed be the negative programmer!