Ask Your Question

Revision history [back]

All you need to know is how to use list comprehensions in Python:

sage: def f(n):
....:     P = Permutations(n)
....:     return [[p,p.reduced_word_lexmin()] for p in P]
....: 
sage: f(2)
[[[1, 2], []], [[2, 1], [1]]]
sage: f(3)
[[[1, 2, 3], []],
 [[1, 3, 2], [2]],
 [[2, 1, 3], [1]],
 [[2, 3, 1], [1, 2]],
 [[3, 1, 2], [2, 1]],
 [[3, 2, 1], [1, 2, 1]]]

Do the following if you need everything to be of type list:

sage: def f(n):
....:     P = Permutations(n)
....:     return [[list(p),p.reduced_word_lexmin()] for p in P]

All you need to know is how to use list comprehensions in Python:

sage: def f(n):
....:     P = Permutations(n)
....:     return [[p,p.reduced_word_lexmin()] for p in P]
P if not p.is_one()]
....: 
sage: f(2)
[[[1, 2], []], [[2, [[[2, 1], [1]]]
sage: f(3)
[[[1, 2, 3], []],
 [[1, 3, 2], [2]],
 [[2, 1, 3], [1]],
 [[2, 3, 1], [1, 2]],
 [[3, 1, 2], [2, 1]],
 [[3, 2, 1], [1, 2, 1]]]

Do the following if you need everything to be of type list:

sage: def f(n):
....:     P = Permutations(n)
....:     return [[list(p),p.reduced_word_lexmin()] for p in P]
P if not p.is_one()]