I want to sort a list from 1.1., 1.2. , 2.,10 given by some lists…
I’m trying to sort a list by part of the sublist value in this case the first column wich has numbers in it.
However if i use SortByKey it transforms my numbers into text and it sorts like 1., 10., 2.,…
I think it is because of the ‘’.’’ but i really need it to be ‘’.’’ and sorted like 1.1., 1.2. , 2.,10
The problem you’ve got initially is that while 6.4 is a number, 6.4.1 isn’t (numbers don’t have more than 1 decimal)… It is probably text, you can use a Type node to check. You also have values like 2.2+2.3
So ideally you’d need a string sorting node which can handle your complexity, unfortunately I’m not aware of one…
Otherwise we’re dealing with converting the number bits to numbers and trying to sort sequently by each “.”
Unfortunately I’m not that bright so i’m trying to work it out…
You’ll need to sequentially sort at level? I’m not sure the best way to do that… This is where I’m at right now…
@Mark.Ackerley , If I didn’t use the “+” like in 2.2+2.3, can it be easier?
I can use another solution for that and it stays like the others with just one value.
Yeah, i think it does need to be sequential… 1st sort by 1st index, then group by 2nd index and sort each group by the 2nd index and then the 3rd, then the 4th…
If you just remove the “.” and sort, then if you have 1.30.1 (1301) it will be put infront of 1.3.31? (1331)
It’s knotty
EDIT : unless we pad? that might work!
Does this work for you? You can always pad by more numbers?
@Mark.Ackerley Nope, it will end up 1.30.1 because I am inserting after the first character then the last;
Issues might happen if there is only one dot, such as 3.1 for example, but it can be solved with an If statement I guess.
You’ve sorted your items using the Python node, they don’t need to be sorted again. You just need to know on which index they are now, because it has changed. To do that, use List.IndexOf, this will give you the sorted indexes and then use List.GetItemAtIndex to get your main list items in the correct order. Basically, something like:
My thoughts about this:
When you have a certain data ranging from 1 to 9 before the first “.” (such as “1.1.1, 2.1, 3.1”), the sort function works fine. However, when mixing those with items whose first digit is greater than 9, before the first “.” (1.1, 10.1, 2.1, 11.5), the sort function will not work like you expect, of course, talking about strings here. This problem happened to one of your examples.