Sort a list containg more than one 2-member list

Sort a list containg more than one 2-member list

scot-65
Advisor Advisor
870 Views
2 Replies
Message 1 of 3

Sort a list containg more than one 2-member list

scot-65
Advisor
Advisor

Can't seem to find an appropriate thread in the archive...

 

I have a list that contains more than one 2-member list.

The format is '(frequency  name).

The first member in the 2-member list is a number. The second is a string.

The 2-member lists are already sorted via the second member.

 

(list

 (2 "Abc")

 (6 "Def")

 (1 "Ghi")

 (2 "Jkl")

)

 

[Using lambda], How do I sort using the first member?

 

(list

 (6 "Def")

 (2 "Abc")

 (2 "Jkl")

 (1 "Ghi")

)

 

Scot-65

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Accepted solutions (1)
871 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

(vl-sort '((2 "Abc") (6 "Def") (1 "Ghi") (2 "Jkl")) '(lambda (a b) (> (car a) (car b))))

returns

((6 "Def") (2 "Abc") (2 "Jkl") (1 "Ghi"))

Kent Cooper, AIA
0 Likes
Message 3 of 3

scot-65
Advisor
Advisor
Thanks.
I was close.

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes