Author Topic: how to count items in a list of lists and make a new list of specifics  (Read 1405 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
sorry in advanced. i didnt know how to proper explain this in a title...
mods feel free to edit it for a better searchable title

i have a list of list.
example
 "abc" "123" "def"
"123" 456" ""
"a1b1" "c2d2" "def"
"123" abc" ""

how can i go thru each item in the list, determine if "def" is in the list
get that list and make a new list of lists

example if "def" is in the list
 "abc" "123" "def"
"a1b1" "c2d2" "def"


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Try this:
Code: [Select]
(setq lst '(( "abc" "123" "def")
            ("123" "456" "")
            ("a1b1" "c2d2" "def")
            ("123" "abc" "")))
(setq target "def")
(vl-remove-if 'null (Mapcar '(lambda(x) (if (member target x) x))  lst))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
^+1
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Another one.
Code: [Select]
(setq lst '(( "abc" "123" "def")
            ("123" "456" "")
            ("a1b1" "c2d2" "def")
            ("123" "abc" "")))
(setq target "def")
(vl-remove-if-not '(lambda (x) (member target x))  lst)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

andrew_nao

  • Guest
both work great CAB, thanks

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
You're welcome.

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.