add to lists inside list

add to lists inside list

DGRL
Advisor Advisor
3,763 Views
21 Replies
Message 1 of 22

add to lists inside list

DGRL
Advisor
Advisor

Dear forum members

 

 

I am looking for a way to add "X" to all lists inside a list

 

This is the list

(("ISO_PIPESPEC" "n.v.t.1" "Prompt 1") ("ISO_MEDIUM" "n.v.t.2" "Prompt 2") ("ISO_DESIGN_PRESS" "n.v.t.3" "Prompt 3"))

 

And I want to get it like this

(("ISO_PIPESPEC" "n.v.t.1" "Prompt 1" "X") ("ISO_MEDIUM" "n.v.t.2" "Prompt 2" "X") ("ISO_DESIGN_PRESS" "n.v.t.3" "Prompt 3" "X"))

 

 

Below is what I tried and didn't work out

 

Trying it like this

(foreach x vier (setq a (append a (car vier) '("X")))) will make 1 long list and I need multiple lists inside a list

 

trying this
(foreach x (car vier) (setq a (append a vier '("")))) will make the list how I want it only it placed the "X" 1 time as last list

 

Trying this

(foreach x vier (setq a (append a x '("")))) will make 1 long list and I need multiple lists inside a list 

Trying this will add the value to each member of the lists

(mapcar '(lambda ( x ) (strcat "insert text here" x)) 'vier)

 

 

 

 

 

vier is the var name I used that contains the list

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Accepted solutions (4)
3,764 Views
21 Replies
Replies (21)
Message 21 of 22

Ranjit_Singh
Advisor
Advisor

Let's say lst was the master list. Since "X" is conveniently placed at the end of every list you could reverse, cdr and reverse again.

-DELETED-

However, if "X" was not the last element (or maybe it was missing from a few of the lists), like this

-DELETED

then below may work

-DELETED-

 EDIT: May apologies. I wasn't reading the whole thread and @Kent1Cooper's reply came as I was typing, else I would had understood your intent. Deleting the code so you can give it a try.

Message 22 of 22

DGRL
Advisor
Advisor

Hi @Ranjit_Singh @Kent1Cooper @ВeekeeCZ @_gile @ActivistInvestor


Thanks to you all for helping me out and most of all for helping me to learn to code lisp

I finished the routine i was working on just a minute ago and it is working perfect.

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes