Ask Your Question

Revision history [back]

I am not sure to understand your question, but you can do:

sage: [((a,b),(b,a)) for (a,b) in m]
[((0, 1), (1, 0)),
 ((0, 2), (2, 0)),
 ((0, 3), (3, 0)),
 ((0, 4), (4, 0)),
 ((0, 5), (5, 0)),
 ((1, 2), (2, 1)),
 ((1, 3), (3, 1)),
 ((1, 4), (4, 1)),
 ((1, 5), (5, 1)),
 ((2, 3), (3, 2)),
 ((2, 4), (4, 2)),
 ((2, 5), (5, 2)),
 ((3, 4), (4, 3)),
 ((3, 5), (5, 3)),
 ((4, 5), (5, 4))]

If you have longer tuples, you can reverse them as follows:

sage: t = (1,2,5,6)
sage: t[::-1]
(6, 5, 2, 1)

So, you can do :

sage: m=itertools.combinations(l,4)
sage: [(t,t[::-1]) for t in m]
[((0, 1, 2, 3), (3, 2, 1, 0)),
 ((0, 1, 2, 4), (4, 2, 1, 0)),
 ((0, 1, 2, 5), (5, 2, 1, 0)),
 ((0, 1, 3, 4), (4, 3, 1, 0)),
 ((0, 1, 3, 5), (5, 3, 1, 0)),
 ((0, 1, 4, 5), (5, 4, 1, 0)),
 ((0, 2, 3, 4), (4, 3, 2, 0)),
 ((0, 2, 3, 5), (5, 3, 2, 0)),
 ((0, 2, 4, 5), (5, 4, 2, 0)),
 ((0, 3, 4, 5), (5, 4, 3, 0)),
 ((1, 2, 3, 4), (4, 3, 2, 1)),
 ((1, 2, 3, 5), (5, 3, 2, 1)),
 ((1, 2, 4, 5), (5, 4, 2, 1)),
 ((1, 3, 4, 5), (5, 4, 3, 1)),
 ((2, 3, 4, 5), (5, 4, 3, 2))]