Author Topic: List - Comparison & Filter  (Read 874 times)

0 Members and 1 Guest are viewing this topic.

Matthew H

  • Newt
  • Posts: 70
List - Comparison & Filter
« 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.
« Last Edit: July 27, 2022, 07:41:25 AM by Matthew H »

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: List - Comparison & Filter
« Reply #1 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")

Matthew H

  • Newt
  • Posts: 70
Re: List - Comparison & Filter
« Reply #2 on: July 27, 2022, 02:21:18 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")

Lee,

That is a wonderful function library!
I was able to get what I need and more, much appreciated!!

Thanks,
Matthew H.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: List - Comparison & Filter
« Reply #3 on: July 27, 2022, 06:13:14 PM »
You're most welcome Matthew - I'm glad you found it useful :-)

BIGAL

  • Swamp Rat
  • Posts: 1419
  • 40 + years of using Autocad
Re: List - Comparison & Filter
« Reply #4 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.
A man who never made a mistake never made anything