# Lists sort by 1.1., 1.2. , 2.,10., ...instead of 1., 10., 2.,

**URL:** <https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747>\
**Category:** Revit\
**Tags:** excel, dynamo\
**Created:** [March 24, 2022, 10:16am UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747 "2022-03-24T10:16:51Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![JI\_NGS](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JI\_NGS](https://forum.dynamobim.com/u/JI_NGS)\
**Post date:** [March 24, 2022, 10:16am UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/1 "2022-03-24T10:16:51Z")

</div>

Hello!

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

Any suggestion would be appreciated!

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/2/327db316d2f7749bb819fc7d1e1bf6bc5e5a4c8b.png)

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [March 24, 2022, 11:00am UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/2 "2022-03-24T11:00:31Z")

</div>

Hello,

you try somethink like this:

 ![2022-03-24_12h00_04](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/9/d95b1188786f0fbb20908e8d106c626f0d908949.png)

---

<div class="post-metadata">

**Author:** ![JI\_NGS](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JI\_NGS](https://forum.dynamobim.com/u/JI_NGS)\
**Post date:** [March 24, 2022, 11:04am UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/3 "2022-03-24T11:04:21Z")

</div>

Hi,

using that “list.Sort” it has the same problem

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/f/cfc499145f520c1b3e0d6f3971dd46bb299c0e1a.png)

---

<div class="post-metadata">

**Author:** ![Mark.Ackerley](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mark.ackerley/32/79310_2.png) [@Mark.Ackerley](https://forum.dynamobim.com/u/Mark.Ackerley)\
**Post date:** [March 24, 2022, 11:09am UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/4 "2022-03-24T11:09:42Z")

</div>

Hey,

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  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/3/23fc729db42765c98deb14b70efe1f520764df5c.png)

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…

 ![1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/4/f4c1bb7dada14f46c9b1d041e55c3f2e3500c2d4.png)

I’ll keep trying…It’s also more complex because your values vary in length…

Hope that helps,

Mark

---

<div class="post-metadata">

**Author:** ![JI\_NGS](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JI\_NGS](https://forum.dynamobim.com/u/JI_NGS)\
**Post date:** [March 24, 2022, 11:53am UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/5 "2022-03-24T11:53:29Z")

</div>

@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.

Thanks!

---

<div class="post-metadata">

**Author:** ![JI\_NGS](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JI\_NGS](https://forum.dynamobim.com/u/JI_NGS)\
**Post date:** [March 24, 2022, 12:35pm UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/6 "2022-03-24T12:35:22Z")

</div>

UPDATE

I’ve tried in a smaller file and it worked with a python Script that i’ve found here in the Forum ([Sorting a list of numbers in a logical order - #2 by JacobSmall](https://forum.dynamobim.com/t/sorting-a-list-of-numbers-in-a-logical-order/64770/2)).

It works until i join that script to “List.SortByKey” then the sort changes again.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/3/c36d31ce5fc4133c68c0a4300520b8d730890b12.png)

---

<div class="post-metadata">

**Author:** ![Elie.Trad](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/elie.trad/32/110373_2.png) [@Elie.Trad](https://forum.dynamobim.com/u/Elie.Trad)\
**Post date:** [March 24, 2022, 1:28pm UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/7 "2022-03-24T13:28:20Z")

</div>

@JI_NGS try this:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/1/a1a638ba7abf9b37399af9594a02ef37c1da106f.png)

---

<div class="post-metadata">

**Author:** ![Mark.Ackerley](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mark.ackerley/32/79310_2.png) [@Mark.Ackerley](https://forum.dynamobim.com/u/Mark.Ackerley)\
**Post date:** [March 24, 2022, 1:54pm UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/8 "2022-03-24T13:54:19Z")

</div>

Hey,

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?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/3/2380a872c9cf3937712b3434ba075ebb907dceb1.png)

---

<div class="post-metadata">

**Author:** ![Elie.Trad](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/elie.trad/32/110373_2.png) [@Elie.Trad](https://forum.dynamobim.com/u/Elie.Trad)\
**Post date:** [March 24, 2022, 2:01pm UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/9 "2022-03-24T14:01:22Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Mark.Ackerley](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mark.ackerley/32/79310_2.png) [@Mark.Ackerley](https://forum.dynamobim.com/u/Mark.Ackerley)\
**Post date:** [March 24, 2022, 2:08pm UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/10 "2022-03-24T14:08:15Z")

</div>

I think in yours, the 3 has become a 30? I might be wrong 🙂 Your idea was definitely the right one…

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/3/e340c08b5c6633f12216948a68b370ba0a93ebdf.png)

> If I didn’t use the “+” like in 2.2+2.3, can it be easier?

Yes I would say that consistancy is going to make your life easier 🙂

Hope that helps,

Mark

EDIT : no, mine fails with numbers with fewer decimals! @EdsonMatt has the answer 🙂

---

<div class="post-metadata">

**Author:** ![EdsonMatt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/edsonmatt/32/124725_2.png) [@EdsonMatt](https://forum.dynamobim.com/u/EdsonMatt)\
**Post date:** [March 24, 2022, 2:20pm UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/11 "2022-03-24T14:20:09Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/5/2555b98c1e5c5f1169dd6426fad2edaedb50ee11.png)

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.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/a/8a347c77392746c49f8d30c221f5bf5017d5d404.png)

So, you can try to sort and get the items in your main list in this way:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/6/c6105c877f6444d0d513fd0d36484f6521c33c9e.png)

```auto
first_itm = DSCore.List.FirstItem(DSCore.String.Split(x,".")<1>);
len = DSCore.String.Length(first_itm);
group = DSCore.List.GroupByKey(x,len)["groups"];
sorted = DSCore.List.Flatten(DSCore.List.Sort(group<1>));
idx = DSCore .List.IndexOf(x,sorted);
get_itms = DSCore.List.GetItemAtIndex(y,idx);

```

---

<div class="post-metadata">

**Author:** ![Elie.Trad](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/elie.trad/32/110373_2.png) [@Elie.Trad](https://forum.dynamobim.com/u/Elie.Trad)\
**Post date:** [March 24, 2022, 2:42pm UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/12 "2022-03-24T14:42:02Z")

</div>

@Mark.Ackerley Ah yes, I see your point.

---

<div class="post-metadata">

**Author:** ![Mark.Ackerley](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mark.ackerley/32/79310_2.png) [@Mark.Ackerley](https://forum.dynamobim.com/u/Mark.Ackerley)\
**Post date:** [March 24, 2022, 2:50pm UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/13 "2022-03-24T14:50:07Z")

</div>

@EdsonMatt has the best solution 🙂

Here in nodes for those of us who get lost in design script!

 ![sorting at level_2022-03-24_02-49-37](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/0/8021f1a6b9917cfee24a425bfb5f4a370ac6563e.png)

---

<div class="post-metadata">

**Author:** ![JI\_NGS](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JI\_NGS](https://forum.dynamobim.com/u/JI_NGS)\
**Post date:** [March 24, 2022, 2:59pm UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/14 "2022-03-24T14:59:17Z")

</div>

@EdsonMatt, it worked!

I used like this (in a larger file)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/7/27b1f2e91a03b1f9801f130d1a4892e9be424ef2.png)

Many many thanks!!

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [March 24, 2022, 11:31pm UTC](https://forum.dynamobim.com/t/lists-sort-by-1-1-1-2-2-10-instead-of-1-10-2/74747/15 "2022-03-24T23:31:26Z")

</div>

Hi @JI_NGS (and the others),

Have you heard about “Natural Sorting”?

For example check out this code:

> [@Sort Numbers](https://forum.dynamobim.com/t/sort-numbers/62083/2):
>
> @gerhard.p 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
