Sort by Mark is Out of Order?

Hi all,

I have a collection of lighting fixtures with a boolean toggle for visibility that i want to control via Dynamo. I’ve managed to group elements by level in an ascending order, now i want to sort that list by the Mark as that is what is being used to number each light.

When i use either List.Sort or List.SortByKey, the Mark value isn’t always in an ascending order, any idea why this may be? Only one of the groups seem to be sorted correctly but the rest are out of order, any ideas?

Thanks

Hi @ppittas,
This has been discussed on this forum in the past and many solutions have been suggested for it.

OOTB approach:

OR

Python approach:

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(x, key=natural_sortkey) for x in IN[0]]

Thanks for that, also found List.SortNatural does the trick too from the Orchid Package.

1 Like