RepCad Posted July 17, 2017 Posted July 17, 2017 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 Quote
ronjonp Posted July 17, 2017 Posted July 17, 2017 (mapcar '(lambda (r j) (list r j)) '(x1 x2 x3 x4 x5 x6 x7) '(y1 y2 y3 y4 y5 y6 y7)) Quote
RepCad Posted July 17, 2017 Author Posted July 17, 2017 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)) Quote
ronjonp Posted July 17, 2017 Posted July 17, 2017 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) Quote
RepCad Posted July 17, 2017 Author Posted July 17, 2017 Thank you very much ronjonp, great, my problem has been resolved:) excuse me for my poor english. Quote
ronjonp Posted July 17, 2017 Posted July 17, 2017 Thank you very much ronjonp, great, my problem has been resolved:)excuse me for my poor english. Glad to help Quote
Lee Mac Posted July 17, 2017 Posted July 17, 2017 It could be reduced to: (setq list1 '("A" "B" "C" "D" "E" "F") list2 '(1 2 3 4 5 6) ) (mapcar 'list list1 list2) Quote
Grrr Posted July 17, 2017 Posted July 17, 2017 Everytime I use (mapcar 'list ... ) in my code it reminds me of Lee, since the guide he gave me. Quote
RepCad Posted July 17, 2017 Author Posted July 17, 2017 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. Quote
ronjonp Posted July 17, 2017 Posted July 17, 2017 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! Quote
RepCad Posted July 17, 2017 Author Posted July 17, 2017 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 : list2 = (x1 x2 x3 x4 x5 x6 x7 x8 ......) best regards Quote
BIGAL Posted July 18, 2017 Posted July 18, 2017 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 ) Quote
abra-CAD-abra Posted July 18, 2017 Posted July 18, 2017 This maybe? (setq list1 '((x1 y1)(x2 y2)(x3 y3)(x4 y4)(x5 y5))) (setq list2 (mapcar 'car list1)) Quote
RepCad Posted July 18, 2017 Author Posted July 18, 2017 This maybe? (setq list1 '((x1 y1)(x2 y2)(x3 y3)(x4 y4)(x5 y5))) (setq list2 (mapcar 'car list1)) Yes it is, thanks alot. Quote
Recommended Posts
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.