Jump to content

add tow list in one list


RepCad

Recommended Posts

Hello everybody,

i have tow list :

list1 = (x1 x2 x3 x4 x5 x6 x7 .....)

list 2 =(y1 y2 y3 y4 y5 y6 y7 .....)

and i want to convert tow list to :

list = ((x1 y1)(x2 y2)(x3 y3)(x4 y4)(x5 y5) .....)

 

how can i do this??

 

Thanks in advance :)

Link to comment
Share on other sites

thank you ronjonp, But it may be more than x7 and y7 ,,,,and I know that the number of two lists is equal,,I entered these codes but i get error :

 

(mapcar '(lambda (r j) (list r j)) '(list1) '(list2))

Link to comment
Share on other sites

thank you ronjonp, But it may be more than x7 and y7 ,,,,and I know that the number of two lists is equal,,I entered these codes but i get error :

 

(mapcar '(lambda (r j) (list r j)) '(list1) '(list2))

 

Take the ' off of your lists.

(setq list1 '("A" "B" "C" "D" "E" "F")
     list2 '(1 2 3 4 5 6)
)
(mapcar '(lambda (r j) (list r j)) list1 list2)

Link to comment
Share on other sites

It could be reduced to:
(setq list1 '("A" "B" "C" "D" "E" "F")
     list2 '(1 2 3 4 5 6)
)
(mapcar 'list list1 list2)

 

thank you lee mac, Your code is brief and perfect.

Link to comment
Share on other sites

It could be reduced to:
(setq list1 '("A" "B" "C" "D" "E" "F")
     list2 '(1 2 3 4 5 6)
)
(mapcar 'list list1 list2)

 

I like it! :)

Link to comment
Share on other sites

Thanks to all the guys ,,,i have another question about list :

how can I create a list of x coordinate in x,y list :

list 1 = ((x1 y1)(x2 y2)(x3 y3)(x4 y4)(x5 y5) ..... )

i want to create : :unsure:

list2 = (x1 x2 x3 x4 x5 x6 x7 x8 ......)

 

best regards

Link to comment
Share on other sites

You can do it a couple of ways I know lee will put forward a lamda solution but you can use a repeat and get each nth of the list then either use another nth or the car of the sublist. The Y is cadr and z is caddr.

 

(setq list1 '("A" "B" "C" "D" "E" "F")
list2 '(1 2 3 4 5 6)
)
(setq lst (reverse (mapcar 'list list1 list2)))
(repeat (setq x (length lst))
(alert (car (nth (setq x (- x 1)) lst))) ; x value is a string 
; (alert (rtos (cadr (nth (setq x (- x 1)) lst)) 2 0)) ; y value is a number 
)

Link to comment
Share on other sites

This maybe?

 

(setq list1 '((x1 y1)(x2 y2)(x3 y3)(x4 y4)(x5 y5)))
(setq list2 (mapcar 'car list1))

 

Yes it is, thanks alot. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...