TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Matthew H on July 26, 2022, 03:19:04 PM
-
I was wondering if anyone could help me figure out how to filter out a list.
If the below does not make since, let me know and I will try to re-word it.
I have two data lists.
ListA '("Item6-2" "Item6" "Item4" "Item8" "Item7" "Item4-12")
ListB '("Item7" "Item3" "Item4-12" "Item9" "Item4" "Item1" "Item5")
I would like to create three separate lists with the following conditions
ListC is ListA, but items that are also in ListB are excluded.
ListC '("Item6-2" "Item6" "Item8")
ListD is ListA, but only items that are also in ListB are included.
ListD '("Item4" "Item7" "Item4-12")
ListE is ListB, but with items in ListA excluded.
ListE '("Item3" "Item9" "Item1" "Item5")
Thanks in advance,
Matthew H.
-
You can use my library of List Set functions for this:
- List Difference (http://lee-mac.com/listdifference.html)
- List Union (http://lee-mac.com/listunion.html)
- List Intersection (http://lee-mac.com/listintersection.html)
- List Symmetric Difference (http://lee-mac.com/listsymdifference.html)
_$ (setq ListC (LM:listdifference ListA ListB))
("Item6-2" "Item6" "Item8")
_$ (setq ListD (LM:listintersection ListA ListB))
("Item4" "Item7" "Item4-12")
_$ (setq ListE (LM:listdifference ListB ListA))
("Item3" "Item9" "Item1" "Item5")
-
You can use my library of List Set functions for this:
- List Difference (http://lee-mac.com/listdifference.html)
- List Union (http://lee-mac.com/listunion.html)
- List Intersection (http://lee-mac.com/listintersection.html)
- List Symmetric Difference (http://lee-mac.com/listsymdifference.html)
_$ (setq ListC (LM:listdifference ListA ListB))
("Item6-2" "Item6" "Item8")
_$ (setq ListD (LM:listintersection ListA ListB))
("Item4" "Item7" "Item4-12")
_$ (setq ListE (LM:listdifference ListB ListA))
("Item3" "Item9" "Item1" "Item5")
Lee,
That is a wonderful function library!
I was able to get what I need and more, much appreciated!!
Thanks,
Matthew H.
-
You're most welcome Matthew - I'm glad you found it useful :-)
-
If you look in the Challenges section of this forum subject there are many solutions to list problems worth a quick look sometimes to see if matches problem.
Not withstanding Lee's great contribution.