# PYTHON - order a list based in another list

**URL:** <https://forum.dynamobim.com/t/python-order-a-list-based-in-another-list/49893>\
**Category:** Revit\
**Tags:** python\
**Created:** [April 27, 2020, 11:54pm UTC](https://forum.dynamobim.com/t/python-order-a-list-based-in-another-list/49893 "2020-04-27T23:54:21Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [April 28, 2020, 12:08am UTC](https://forum.dynamobim.com/t/python-order-a-list-based-in-another-list/49893/2 "2020-04-28T00:08:24Z")

</div>

To sort by Z then X then Y use the following:

```
import clr
orglst = IN[0]
orglst.sort(key = lambda orglst: (orglst.Z, orglst.X, orglst.Y))
OUT = orglst

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/1/a116fb48821774c186fa169946895efe74184c67.png)

Adaption of the code by:

> [@List sort by key by z then by y then by x location](https://forum.dynamobim.com/t/list-sort-by-key-by-z-then-by-y-then-by-x-location/23227/5):
>
> You could try something like this: import clr orglst = IN[0] orglst.sort(key = lambda orglst: (orglst.X, orglst.Y, orglst.Z)) OUT = orglst

---

_[View the full topic](https://forum.dynamobim.com/t/python-order-a-list-based-in-another-list/49893)._
