Sorting Family type in ascending order

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 (45.7 KB)

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)

2 Likes

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…

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 “-”.

Thank you I ll check…

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

@rajkumar.kolli93 I’ve update the code for you. See if this works. FamilySort.dyn (10.2 KB)

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)
1 Like

Thank your@AmolShah . I ll check with this…