TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Matthew H on July 26, 2022, 03:19:04 PM

Title: List - Comparison & Filter
Post 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.
Title: Re: List - Comparison & Filter
Post by: Lee Mac on July 26, 2022, 05:47:26 PM
You can use my library of List Set functions for this:
Code: [Select]
_$ (setq ListC (LM:listdifference ListA ListB))
("Item6-2" "Item6" "Item8")
Code: [Select]
_$ (setq ListD (LM:listintersection ListA ListB))
("Item4" "Item7" "Item4-12")
Code: [Select]
_$ (setq ListE (LM:listdifference ListB ListA))
("Item3" "Item9" "Item1" "Item5")
Title: Re: List - Comparison & Filter
Post by: Matthew H on July 27, 2022, 02:21:18 PM
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)
Code: [Select]
_$ (setq ListC (LM:listdifference ListA ListB))
("Item6-2" "Item6" "Item8")
Code: [Select]
_$ (setq ListD (LM:listintersection ListA ListB))
("Item4" "Item7" "Item4-12")
Code: [Select]
_$ (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.
Title: Re: List - Comparison & Filter
Post by: Lee Mac on July 27, 2022, 06:13:14 PM
You're most welcome Matthew - I'm glad you found it useful :-)
Title: Re: List - Comparison & Filter
Post by: BIGAL on July 27, 2022, 09:05:34 PM
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.