Sort sublists in general lisp

Very simple

with this, (sort L #'> :key #'second)) , I can sort, (((C) 1) ((D) 1) ((E) 1) ((F) 1) ((G) 1) ((H) 1) ((B) 3) ((A) 8))

But now I want to sort ((((A) 8)) (((B) 3)) (((C) 1)) (((D) 1)) (((E) 1)) (((F) 1)) (((G) 1)) (((H) 1))) .

What do I need to do (sort L #'> :key #'second)) to sort the second list?

+4
source share
1 answer

I hope I understood your question correctly.

You need :key (lambda (x) (second (car x))) .

However, you don't even need lambda :

 (cadar '(((A) 8))) ==> 8 

therefore :key #'cadar is your friend.

+6
source

All Articles