Good day, I have this nested list:

```
Xs = [ [Joe, Pilot, 100], [Stan, Co-Pilot, 300], [Steve, Pilot, 150], ].
```

How can I sort this nested list in order to do the following: (Using the third element in descending order)

```
Xs = [ [Stan, Co-Pilot, 300], [Steve, Pilot, 150], [Joe, Pilot, 100] ]. ?
```

# Best How To :

Define:

```
criteria(R,[_,_,N1],[_,_,N2]) :- compare(R,N2,N1).
```

and use "predsort/3" like in:

```
?- predsort(criteria,[ [Joe, Pilot, 100], [Stan, Co-Pilot, 300], [Steve, Pilot, 150] ], Xs).
Xs = [[Stan, Co-Pilot, 300], [Steve, Pilot, 150], [Joe, Pilot, 100]].
```

If duplicated third elements can exists, "criteria" must be changed. By example as:

```
criteria(R,[_,_,N1],[_,_,N2]) :- N1=\=N2, !, compare(R,N2,N1).
criteria(R,E1,E2) :- compare(R,E1,E2).
```