Sort numbers in correct order

Hi. I do want to sort a list of numbers in alphabetical order, means 0,1 … 9, 10,11 … 19,20, … 99, 100, etc, bet instead I do have a list like 1,10,11,etc.

How can I do this kind of sorting?

Sort_Numbers
Sort_Numbers.gh (7.9 KB)

This is one way

1 Like

You have a tree, not a list.

Flatten the tree and use Sort List for numerical order or Sort Text for alphabetical order - it seems you want the first one with your example.

Sort_Numbers.gh (11.8 KB)

And how I can sort the original data from the Data input? If I do pass that information into the Sort List component I do get an error. My definition was just an attempt to sort the input data.

You need to do some text pre processing before you can sort your data.

Unfortunately don’t works with more complicated data.

Sort_Numbers_more.gh (14.0 KB)

Actually this example is simpler than your original.

1 Like

Thank you for this solution. I do figured also by myself using your first definition but using a quite ugly List Item and Concatenate to decompose and recompose the initial data which resulted into a quite big cluster.

1 Like

Hi, is it possible to apply this to data that has letters in it also? I was struggling to apply the above to what Im trying to do. Essentially my end goal is for the list to have the below list read in the correct order.

Hi @Hayden_Payne,

Python to the rescue.

natural_sort.gh (6.0 KB)

– Dale

1 Like

Thanks Dale! That works well. I have another similar one with similar applications but I need to maintain the properties of the Views to be able to place on a sheet but in the natural order? is this possible?

@Hayden_Payne You need the index It would be easier to obtain it within the code but I am still with R7 and can’t acces to the new Script Editor @dale.
Anyway you could find it externally with FindSimilarMember component.

@ThomasE - this should work in V7.

natural_sort_v7.gh (6.4 KB)

– Dale

2 Likes

Nice. It is possible to add an additional input-output to sort also the geometry IDs correspondingly? I am interested on sorting some geometry IDs by the names of the geometry. Best regards.

Thank you @dale For learning purposes, is there any possibility to translate your python to C# using the same logic? :pray:t2: :slightly_smiling_face:

@Cumberland try this.


sortByName.gh (13 KB)

1 Like

@ThomasE - If you Google, you’ll find lots of examples.

natural_sort_v8.gh (6.0 KB)

– Dale

1 Like