Transforming a list of lists

Transforming a list of lists

Browning_Zed
Advocate Advocate
645 Views
7 Replies
Message 1 of 8

Transforming a list of lists

Browning_Zed
Advocate
Advocate

Dear sirs, tell me how to resolve the issue.
How can I transform a list like this:
((Vol-1 ("A" "B") ("C" "D") ("E" "F")) (Vol-2 (1 2) (3 4) (5 6)) (Vol-3 (x x) (y y) (z z)))
to a list of this form:
(("A" "B") ("C" "D") ("E" "F") (1 2) (3 4) (5 6) (x x) (y y) (z z))
Thank you in advance for your help.

0 Likes
Accepted solutions (2)
646 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

(apply 'append (mapcar 'cdr lst))

Message 3 of 8

john.uhden
Mentor
Mentor

@ВeekeeCZ 

Blast it all.  You beat me.  Y'know, I have to work now and then.  😕

John F. Uhden

0 Likes
Message 4 of 8

pbejse
Mentor
Mentor
Accepted solution

@Browning_Zed wrote:

How can I transform a list like this:
((Vol-1 ("A" "B") ("C" "D") ("E" "F")) (Vol-2 (1 2) (3 4) (5 6)) (Vol-3 (x x) (y y) (z z)))
to a list of this form:
(("A" "B") ("C" "D") ("E" "F") (1 2) (3 4) (5 6) (x x) (y y) (z z))


And because the #1 Draft pick is already taken. Here's an alternative solution

(Defun _theRestI (l / i nl)
  (repeat (setq i (length l))
    (setq nl (append (cdr (nth (setq i (1- i)) l)) nl))
  )
  nl
)
_$ (setq lst '((Vol-1 ("A" "B") ("C" "D") ("E" "F")) (Vol-2 (1 2) (3 4) (5 6)) (Vol-3 (x x) (y y) (z z))))
((VOL-1 ("A" "B") ("C" "D") ("E" "F")) (VOL-2 (1 2) (3 4) (5 6)) (VOL-3 (X X) (Y Y) (Z Z)))
_$ (apply 'append (mapcar 'cdr lst))
(("A" "B") ("C" "D") ("E" "F") (1 2) (3 4) (5 6) (X X) (Y Y) (Z Z))
_$ (_theRestI lst)
(("A" "B") ("C" "D") ("E" "F") (1 2) (3 4) (5 6) (X X) (Y Y) (Z Z))

HTH

 

Message 5 of 8

john.uhden
Mentor
Mentor

@pbejse 

I intend to get drafted before you do...

(though the last time there was a draft I joined the National Guard instead)

(Defun _theRestJU (l / nl)
  (while l
    (setq nl (append nl (cdar l)) l (cdr l))
  )
  nl
)

 

John F. Uhden

Message 6 of 8

pbejse
Mentor
Mentor
(defun _theRestR (l)
  (if l
    (append (cdr (Car l)) (_theRestR (cdr l))))
  )
Message 7 of 8

hak_vz
Advisor
Advisor

Here is another one collected from some old LISP book, basically equal to @ВeekeeCZ 

 

(setq lst '((Vol-1 ("A" "B") ("C" "D") ("E" "F")) (Vol-2 (1 2) (3 4) (5 6)) (Vol-3 (x x) (y y) (z z))))

(defun mappend (fn lst)(apply 'append (mapcar fn lst)))
(mappend 'cdr lst)
(("A" "B") ("C" "D") ("E" "F") (1 2) (3 4) (5 6) (X X) (Y Y) (Z Z))

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 8 of 8

john.uhden
Mentor
Mentor
@pbejse
Recursion beats me every time. Nice!
You're drafted. Except you ship out the day after Labor Day. 😕

John F. Uhden