Message 1 of 6
Get ent with max value using APPLY and MAPCAR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I was trying figure out how to get entity name with max number using apply and mapcar.
Example
(setq lst '(("<Entname1>" . 1) ("<Entname2>" . 3) ("<Entname3>" . 2))) ;Goal: Get Entname with max number: ;Result: "<Entname2>" ;PS. String syntax is just for test purpose.
I came up with: (but for opposite order in pairs...)
Spoiler
(setq emax (cdr (assoc (apply 'max (mapcar 'car lst)) lst)))
Maybe using vl-sort.... but I'am pretty sure there must be better way than using assoc or vl-sort... I have have too little experience with this... Thx.