# Obtaining a poset from Posets(n)

I have defined function that takes a poset $P$ as input and outputs the major index generating polynomial over all linear extensions of $P$. Here, the major index of a certain linear extension of $P$ is given by the major index of the corresponding permutation, see e.g. http://mathworld.wolfram.com/LinearEx... for an example of this correspondence.

```
def major_index(pos):
poly = 0
lst = pos.linear_extensions()
for le in lst:
perm = Permutation(x.element for x in le)
maj = perm.major_index()
poly += x^maj
return poly
```

If I write, for example

```
P = Poset(([1,2,3,4], [[1,3],[1,4],[2,3]]), linear_extension=True, facade=False)
major_index(P)
```

Then I get

```
x^4 + x^3 + x^2 + x + 1
```

which is the correct output. I would like to use Posets(n) to generate all posets (up to isomorphism) with $n$ vertices. However, when I write

```
lst = Posets(3)
P = lst[3]
major_index(P)
```

I get the error:

```
Traceback (click to the left of this block for traceback)
...
AttributeError: 'sage.rings.integer.Integer' object has no attribute
'element'
```

Clearly the error is due to the line

```
perm = Permutation(x.element for x in le)
```

But I don't understand how Posets(n) works and why I cannot just write lst[3] to obtain a poset.