List transformation

List transformation

Browning_Zed
Advocate Advocate
536 Views
6 Replies
Message 1 of 7

List transformation

Browning_Zed
Advocate
Advocate

Hi all.
I need help changing the list. The original list has the following format:
'((2.1 3.5 0.0) (10.9 11.2 3.6) (12.4 19.7 5.5))
it needs to be converted to a list of this format:
'(2.1 3.5 10.9 11.2 12.4 19.7)
that is, in the original list should remove the third item of each sublist, and transform the original list from a nested list to a simple list. In other words, the elements of the original list marked in red must be deleted.

0 Likes
Accepted solutions (2)
537 Views
6 Replies
Replies (6)
Message 2 of 7

hak_vz
Advisor
Advisor
Accepted solution

 

(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
(defun take2 (lst) (take 2 lst))
(apply 'append(mapcar 'take2 '((2.1 3.5 0.0) (10.9 11.2 3.6) (12.4 19.7 5.5))))
(2.1 3.5 10.9 11.2 12.4 19.7)

 

@Browning_Zed 

I guess you've received this functions before. It's time to start using them.

 

 

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.
0 Likes
Message 3 of 7

-didier-
Advisor
Advisor
Accepted solution

Bonjour @Browning_Zed 

 

Here is my proposal to do this task

 

Amicalement

(apply 'append (mapcar (function (lambda (x) (reverse (cdr (reverse x))))) l1))

 

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

Message 4 of 7

Browning_Zed
Advocate
Advocate

Thanks for the help. What function are we talking about?

0 Likes
Message 5 of 7

Browning_Zed
Advocate
Advocate

Thank you very much.

0 Likes
Message 6 of 7

hak_vz
Advisor
Advisor

@Browning_Zed wrote:

Thanks for the help. What function are we talking about?


Function take, I use it regularly in my codes, and variations with apply mapcar. 

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.
0 Likes
Message 7 of 7

Browning_Zed
Advocate
Advocate

Got it, thanks.

0 Likes