Sort List by Order of Another List

Hello all,

I need list 2 to be sorted the same way as list 1.

I feel like I’ve scoured through this forum and other sources, but seem to have hit a wall. It feels like such a simple thing, so let me know if this has already been solved. This is the last thing I need to make this script functional.

Idea of this is to sort list 2 back to list 1 so that the elements (doors) will be assigned their parameter (mark) in the right order. I could resort the list of elements (doors) to list 2, but I feel like the former may result in a simpler solution. (I would post the script but new users can only post 1 image at a time).

Edit: I am actually thinking there is no way to do this in the base Dynamo program. Would anyone have a work around/python script that would be able to “see” the order of list 1 and sort list 2 the same way?

@htartersauce a couple of points that may help!

  1. It’s typically easier to create a Dictionary of elements earlier in your graph, then simply refer to them with your key. In this case, could be the Mark value.
  2. If you still want to simply match these two lists, you can try “Regular Expressions” to do so, or take some form of the approach below in the image.

It really depends on if a single entry of List 1 1-RH105 can pair with any 1-RH105A/B/C from List 2.

1 Like

I will edit the original post, but the sorting of the lists cannot depend on any external factor outside of the objects of the list. List 2 must be sorted back to the same order as list 1. Perhaps converting to string and grabbing the “starts with” may yield better results?

The problem is flawed, as you have repeated items in your list, which do not have a logical order if they occur out of order. Work backwards from the point where you have those lists and get objects that are more reliable keys to keep in parallel, such as an element Id or Guid. If the data comes from Excel, build a range to the same length as the column and use those to track data movement in parallel.

3 Likes