for i in range(len(x)):
for el in x[:i] + x[(i+1):]:
print("Compare {} with {}".format(x[i], el))
# or: Compare(x[i], el)
"""
Output:
Compare a with b
Compare a with c
Compare a with d
Compare b with a
Compare b with c
Compare b with d
Compare c with a
Compare c with b
Compare c with d
Compare d with a
Compare d with b
Compare d with c
"""
Как функция:
def exclusive_compare(l, comparefun):
return [comparefun(l[i], el) for el in l[:i] + l[(i+1):] for i in range(len(l))]
exclusive_compare(l, lambda x, y: (x, y))
Out[9]:
[('a', 'b'),
('a', 'c'),
('a', 'd'),
('b', 'a'),
('b', 'c'),
('b', 'd'),
('c', 'a'),
('c', 'b'),
('c', 'd'),
('d', 'a'),
('d', 'b'),
('d', 'c')]