Sort By Type Name

I’m trying to sort this list of structural framings by their type names, but the sorting is like CB1-CB10-CB11, I need it to be CB1-CB2,CB3, etc, Can anyone help? - I’m sure this is basic stuff but I just can’t figure it out.

Need only sort or need to group also?

like this?

sort.dyn (15.0 KB)

@janbarsoum You need something called natural sort.

Try this:

import re

def natural_sort(l): 
    convert = lambda text: int(text) if text.isdigit() else text.lower() 
    alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] 
    return sorted(l, key = alphanum_key)
OUT = natural_sort(IN[0])

Alternatively, you can use the Natural Sort node from Orchid package


Yes this is basic stuff:

1 Like