JSYoung81 Posted December 3, 2014 Share Posted December 3, 2014 I am struggling over combining 2 different lists. Elements from list 1 contains, lets say, 1 2 3, while elements from list 2 are A B C D. The master list would look something like this: 1 A 1 B 1 C 1 D 2 A 2 B 2 C And so on. I think I need to use the FOREACH function, but just not sure. Any help would be great. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 3, 2014 Share Posted December 3, 2014 You can use nth to get each individual value and then say Strcat to make the new value. (setq list1 (list 1 2 3 4 5 6 7)) (setq list2 (list "a" "b" "c" "d" "e" "f" "g")) (setq len (length list1)) ; I would check here that list1 is same number as list2 (setq x 0) (repeat len (Princ (strcat "\n" (rtos (nth x list1) 2 0) " " (nth x list2))) (setq x (+ x 1)) ) Quote Link to comment Share on other sites More sharing options...
JSYoung81 Posted December 3, 2014 Author Share Posted December 3, 2014 They are unequal lists Quote Link to comment Share on other sites More sharing options...
BlackBox Posted December 3, 2014 Share Posted December 3, 2014 Not sure I understand the desired output, so here are two adaptations: (mapcar (function (lambda (x y) (cons x y)) ) '(1 1 1 1 2 2 2) '("A" "B" "C" "D" "A" "B" "C") ) (mapcar (function (lambda (x y) (list x y)) ) '(1 1 1 1 2 2 2) '("A" "B" "C" "D" "A" "B" "C") ) More information is needed. Quote Link to comment Share on other sites More sharing options...
JSYoung81 Posted December 3, 2014 Author Share Posted December 3, 2014 RANGE_LIST = [["RANGE 1" 1.0 ] ["RANGE 2" 2.0 ] ["RANGE 3" 3.0 ] ["RANGE 4" 4.0 ] ["RANGE 5" 5.0 ]] PART_SIZE_LIST = [["AC" 0.1] ["PVC" 0.5]] End result would be a list that would look like this: MASTER_LIST = [["AC" 0.1 "RANGE 1" 1.0 ] ["AC" 0.1 "RANGE 2" 2.0 ]....... Basically I want to add each element of the range_list to each element of the part_size_list to create a brand new element in the master_list. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 3, 2014 Share Posted December 3, 2014 Try this it is a variation on using nth (setq list1 (list 1 2 3 4 5 6 7)) (setq list2 (list "a" "b" "c" "d" "e" "f" "g")) (setq len (length list1)) ; I would check here that list1 is same number as list2 (setq x 0) (setq Y (- (Getint "\nEnter item Number from list2") 1)) (repeat len (Princ (strcat "\n" (rtos (nth x list1)2 0) " " (nth Y list2))) ; dont need rtos if strings (setq x (+ x 1)) ) Quote Link to comment Share on other sites More sharing options...
hmsilva Posted December 3, 2014 Share Posted December 3, 2014 Something like this, perhaps... (setq a '(("RANGE 1" 1.0)("RANGE 2" 2.0)("RANGE 3" 3.0)("RANGE 4" 4.0)("RANGE 5" 5.0)) b '(("AC" 0.1) ("PVC" 0.5)) ) (foreach x b (setq n -1) (while (setq y (nth (setq n (1+ n)) a)) (setq c (cons (append x y) c)) ) ) (setq c (reverse c)) Henrique Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 3, 2014 Share Posted December 3, 2014 Maybe: (setq a '(("RANGE 1" 1.0)("RANGE 2" 2.0)("RANGE 3" 3.0)("RANGE 4" 4.0)("RANGE 5" 5.0)) b '(("AC" 0.1) ("PVC" 0.5)) ) (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) (append x y)) a)) b) Or, if a single list is required: (apply 'append (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) (append x y)) a)) b)) Quote Link to comment Share on other sites More sharing options...
hmsilva Posted December 4, 2014 Share Posted December 4, 2014 Or, if a single list is required: (apply 'append (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) (append x y)) a)) b)) Nicely done. Henrique Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 4, 2014 Share Posted December 4, 2014 Nicely done. Henrique Thanks! Quote Link to comment Share on other sites More sharing options...
JSYoung81 Posted December 4, 2014 Author Share Posted December 4, 2014 Maybe: (setq a '(("RANGE 1" 1.0)("RANGE 2" 2.0)("RANGE 3" 3.0)("RANGE 4" 4.0)("RANGE 5" 5.0)) b '(("AC" 0.1) ("PVC" 0.5)) ) (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) (append x y)) a)) b) Or, if a single list is required: (apply 'append (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) (append x y)) a)) b)) Lee as always you are brilliant, works just as I need it to, for the most part, just have to reverse a few things. But perfect! Thank you very much! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 4, 2014 Share Posted December 4, 2014 Lee as always you are brilliant, works just as I need it to, for the most part, just have to reverse a few things. But perfect! Thank you very much! Thank you for your flattering comments JSYoung, I'm happy to help Quote Link to comment Share on other sites More sharing options...
JSYoung81 Posted December 4, 2014 Author Share Posted December 4, 2014 No problem, I am sure I am going to need a bit more help by the time I am done this LISP. The entire idea behind this LISP is to be able to have a complete pipe depth list, sorted by ranges and different types of pipe used. Quote Link to comment Share on other sites More sharing options...
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.