# Sorting Family type in ascending order

**URL:** <https://forum.dynamobim.com/t/sorting-family-type-in-ascending-order/60428>\
**Category:** Revit\
**Tags:** dynamo\
**Created:** [February 13, 2021, 3:49pm UTC](https://forum.dynamobim.com/t/sorting-family-type-in-ascending-order/60428 "2021-02-13T15:49:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajkumar.kolli93](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/rajkumar.kolli93/32/103187_2.png) [@rajkumar.kolli93](https://forum.dynamobim.com/u/rajkumar.kolli93)\
**Post date:** [February 13, 2021, 3:49pm UTC](https://forum.dynamobim.com/t/sorting-family-type-in-ascending-order/60428/1 "2021-02-13T15:49:44Z")

</div>

Dear All,  
Help me to crack this logic.

I’m not getting family types in order like series. Is there any way to get all family types in order.

Thanks in advance.

Below I attached my graph for reference.  
[Family Type sorting.dyn](https://forum.dynamobim.com/uploads/short-url/60jAyGXg6v2rU7WgZm1PSVvmlFF.dyn) (45.7 KB)

 ![2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/1/1110f3a1a87283d69b3594ea555ea62b161153ba.png)

---

<div class="post-metadata">

**Author:** ![AmolShah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/amolshah/32/103244_2.png) [@AmolShah](https://forum.dynamobim.com/u/AmolShah)\
**Post date:** [February 14, 2021, 2:57am UTC](https://forum.dynamobim.com/t/sorting-family-type-in-ascending-order/60428/2 "2021-02-14T02:57:22Z")

</div>

Hi @rajkumar.kolli93 ,  
I think Natural Sort can help you here.

```
import re
tokenize = re.compile(r'(\d+)|(\D+)').findall

def natural_sortkey(string):          
    return tuple(int(num) if num else alpha for num, alpha in tokenize(string))

OUT = sorted(IN[0], key=natural_sortkey)

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/b/eb656d677bd4b45ebdf6dfad8a3b4196aaf48ae0.png)

---

<div class="post-metadata">

**Author:** ![rajkumar.kolli93](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/rajkumar.kolli93/32/103187_2.png) [@rajkumar.kolli93](https://forum.dynamobim.com/u/rajkumar.kolli93)\
**Post date:** [February 14, 2021, 10:32am UTC](https://forum.dynamobim.com/t/sorting-family-type-in-ascending-order/60428/3 "2021-02-14T10:32:36Z")

</div>

Thank you for your reply. But still in your graph last node showing result not in order. I want to extract like 1,2,3,4…n…

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [February 14, 2021, 11:06am UTC](https://forum.dynamobim.com/t/sorting-family-type-in-ascending-order/60428/4 "2021-02-14T11:06:56Z")

</div>

Hi @rajkumar.kolli93 ,

The last node from the solution of @AmolShah sorts the list with “Family…” so it matches the list with your codes.  
If you only want to extract the numbers i would suggest splitting your names by “-”.

---

<div class="post-metadata">

**Author:** ![rajkumar.kolli93](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/rajkumar.kolli93/32/103187_2.png) [@rajkumar.kolli93](https://forum.dynamobim.com/u/rajkumar.kolli93)\
**Post date:** [February 14, 2021, 11:34am UTC](https://forum.dynamobim.com/t/sorting-family-type-in-ascending-order/60428/5 "2021-02-14T11:34:43Z")

</div>

Thank you I ll check…

---

<div class="post-metadata">

**Author:** ![rajkumar.kolli93](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/rajkumar.kolli93/32/103187_2.png) [@rajkumar.kolli93](https://forum.dynamobim.com/u/rajkumar.kolli93)\
**Post date:** [February 14, 2021, 1:45pm UTC](https://forum.dynamobim.com/t/sorting-family-type-in-ascending-order/60428/6 "2021-02-14T13:45:27Z")

</div>

Hi,  
Can u send the your dynamo file… for me python showing error in last line and I’m not good in python scripting

---

<div class="post-metadata">

**Author:** ![AmolShah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/amolshah/32/103244_2.png) [@AmolShah](https://forum.dynamobim.com/u/AmolShah)\
**Post date:** [February 14, 2021, 4:38pm UTC](https://forum.dynamobim.com/t/sorting-family-type-in-ascending-order/60428/7 "2021-02-14T16:38:09Z")

</div>

@rajkumar.kolli93 I’ve update the code for you. See if this works. [FamilySort.dyn](https://forum.dynamobim.com/uploads/short-url/tcXGWqo4r0SjirjrPP3DuDBdF7x.dyn) (10.2 KB)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/e/fe1818044e5cae23acc608a3e5f865b1d2fce7fd.png)

```
import re
tokenize = re.compile(r'(\d+)').findall

splitText = [i.split("-")[1] for i in IN[0]]

def natural_sortkey(string):          
    return tuple(int(num) for num in tokenize(string))

OUT = splitText,sorted(splitText, key=natural_sortkey)
```

---

<div class="post-metadata">

**Author:** ![rajkumar.kolli93](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/rajkumar.kolli93/32/103187_2.png) [@rajkumar.kolli93](https://forum.dynamobim.com/u/rajkumar.kolli93)\
**Post date:** [February 17, 2021, 11:50am UTC](https://forum.dynamobim.com/t/sorting-family-type-in-ascending-order/60428/8 "2021-02-17T11:50:40Z")

</div>

Thank your@AmolShah . I ll check with this…
