RepCad Posted November 1, 2022 Share Posted November 1, 2022 Hello everyone, I have a function for removing duplicate items from a list : (defun LM:Unique (l) (if l (cons (car l) (LM:Unique (vl-remove (car l) (cdr l)))) ) ) I want to change and use it on this list type : (that must compare first item of each list) (("301" x y) ("304" x y) ("301" x y) ("331" x y) ("345" x y) ("304" x y) ("359" x y)) >> (("301" x y) ("304" x y) ("331" x y) ("345" x y) ("359" x y)) * x or y can be different and does not matter in comparison. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
robierzo Posted November 1, 2022 Share Posted November 1, 2022 (edited) this is a possibility (defun elimina ( l ) (if l (cons (car l) (elimina (vl-remove-if '(lambda ( x ) (= (caar l) (car x))) (cdr l))))) ) Edited November 1, 2022 by robierzo 1 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 1, 2022 Share Posted November 1, 2022 Another - (defun f ( l / r ) (foreach x l (or (assoc (car x) r) (setq r (cons x r)))) (reverse r) ) 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.