Sort a list by another unequal length list?

Sort a list by another unequal length list?

mid-awe
Collaborator Collaborator
1,122 Views
6 Replies
Message 1 of 7

Sort a list by another unequal length list?

mid-awe
Collaborator
Collaborator

Hi all,

 

I am banging my head over this. I am building a block-table. As the blocks are found and counted I need to sort the list of blocks to a specific order. Currently I am sorting the blocks in alphabetical order, but I need to change that to order the blocks counted into an order of importance. If someone can set me in the right direction, I would be most appreciative. 

 

; MASTER LIST
(LIST "VECTOR" "ROTATING" "STEP" "FIXEDSIZE" "FIXEDQTY" "6PORT" "9PORT" "12PORT" "2PORT4GEAR" "3PORT" "SF360" "CANISTER" "EDC" "FUSECANISTER" "VENTURI" "JET" "SWINGJET" "UV" "JETPACK" "O3" "AIRPORT" "SDX" "LEVELER" "SCOPE" "AIRBAR")

; POSSIBLE LIST BASED ON BLOCKS FOUND IN DRAWING
(LIST "3PORT" "9PORT" "AIRBAR" "ROTATING" "STEP" "FIXEDSIZE" "FIXEDQTY" "SF360" "EDC" "VENTURI" "UV" "O3" "SDX" "LEVELER" "VECTOR")



; THE LIST AFTER BEING SORTED ACCORDING TO THE MASTER LIST
(LIST "VECTOR" "ROTATING" "STEP" "FIXEDSIZE" "FIXEDQTY" "9PORT" "3PORT" "SF360" "EDC" "VENTURI" "UV" "O3" "SDX" "LEVELER" "AIRBAR")

All my attempts have failed. Please help.

 

Thank you in advance for any suggestions.

0 Likes
Accepted solutions (1)
1,123 Views
6 Replies
Replies (6)
Message 2 of 7

Shneuph
Collaborator
Collaborator
Accepted solution

I'm not sure if this is a no no.. But, what if you start with your master list and then remove items if the members of your drawing list are not members?

 

 

; MASTER LIST
(setq mlist (LIST "VECTOR" "ROTATING" "STEP" "FIXEDSIZE" "FIXEDQTY" "6PORT" "9PORT" "12PORT" "2PORT4GEAR" "3PORT" "SF360" "CANISTER" "EDC" "FUSECANISTER" "VENTURI" "JET" "SWINGJET" "UV" "JETPACK" "O3" "AIRPORT" "SDX" "LEVELER" "SCOPE" "AIRBAR")
  mylist (LIST "3PORT" "9PORT" "AIRBAR" "ROTATING" "STEP" "FIXEDSIZE" "FIXEDQTY" "SF360" "EDC" "VENTURI" "UV" "O3" "SDX" "LEVELER" "VECTOR")
      );setq

(foreach x mlist
  (if (not (member x mylist))
    (setq mlist (vl-remove x mlist))
    );if
    );foreach

Just the 1st thing that came to mind.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 3 of 7

mid-awe
Collaborator
Collaborator
Thank you. That may work. Good thinking.
0 Likes
Message 4 of 7

john.uhden
Mentor
Mentor
It may not be a significant difference with short lists, but I have found that vl-position works a lot faster than member.

John F. Uhden

Message 5 of 7

patrick_35
Collaborator
Collaborator

Hi

 

An another

 

(setq mlist (LIST "VECTOR" "ROTATING" "STEP" "FIXEDSIZE" "FIXEDQTY" "6PORT" "9PORT" "12PORT" "2PORT4GEAR" "3PORT" "SF360" "CANISTER" "EDC" "FUSECANISTER" "VENTURI" "JET" "SWINGJET" "UV" "JETPACK" "O3" "AIRPORT" "SDX" "LEVELER" "SCOPE" "AIRBAR")
      mylist (LIST "3PORT" "9PORT" "AIRBAR" "ROTATING" "STEP" "FIXEDSIZE" "FIXEDQTY" "SF360" "EDC" "VENTURI" "UV" "O3" "SDX" "LEVELER" "VECTOR")
)

(vl-remove-if-not '(lambda(x)(vl-position x mylist)) mlist)

 

@+

0 Likes
Message 6 of 7

mid-awe
Collaborator
Collaborator
Thank you all. I'll give it a another go with these great suggestions. I'm sure these solutions will work.
0 Likes
Message 7 of 7

mid-awe
Collaborator
Collaborator
Afterall I went this direction. MyList is actually dotted pairs and it was much easier to get my data where I needed it like you have it here. Thank you Shneuph.
0 Likes