Jump to content

Return the longest list in an association list


Recommended Posts

Posted

Hello fellow hackers,

 

A simple question where I'm still struggling to find an answer:

 

"I have an association list (just like you would get using (entget (car (entsel))), except that they're not dotted pairs, they're lists (all of them). How can you retrieve the longest or shortest list from that association list?"

 

Thanks,

Jonathan Handojo

Posted

Lol, actually... forget it 🤣 

(nth (vl-position (apply 'max (mapcar 'length lst)) (mapcar 'length lst)) lst)

 

Posted

Alternatively -

(nth (car (vl-sort-i (mapcar 'length lst) '>)) lst)

Though sorting to find an extremum is likely to be slower in general.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...