def all_pairs(seq): """Produce all pairs from seq, but not (a, a)""" return itertools.combinations(seq, 2)