Let $S\_n$ be the symmetric group over $\{1,2,\ldots,n\}$. How to return elements of length $m$ in $S\_n$ using Sage? I try to find such function in Sage but didn't find one. Thank you very much.


Edit: $S\_n$ is the Coxeter group of type $A$ generated by $s\_1=(12), \ldots, s\_{n-1}=(n-1,n)$. The length of an element $w \in S\_n$ is the least number of simple
reflections $s\_i$ occurring in any expression for $w$.



How to return elements of a given length in a symmetric group using Sage?
You can enumerate words of a given length in any Coxeter group using the function `elements_of_length`. Here is an example of using this for a Coxeter group I studied recently:



```
sage: CM = CoxeterMatrix([[1,2,-1,-1,2],[2,1,2,-1,-1],[-1,2,1,2,-1],[-1,-1,2,1,2],[2,-1,-1,2,1]])
sage: G = CoxeterGroup(CM, base_ring=ZZ)
sage: G.elements_of_length(3)
<generator object _elements_of_depth_iterator_rec at 0x1af3f0eb0>

```

The returned object is an iterator. So you can do things like



```
sage: for g in G.elements_of_length(1): print G

```

