Jump to content

how to combine two list into one as follows?


CANDOWE

Recommended Posts

original lists:

(setq list1 '(a b c))

(setq list2 '(x y z))

 

results should be like this:

(setq list3 '('(a x) '(a y) '(a z) '(b x) '(b y) '(b z) '(c x) '(c y) '(c z))

Link to comment
Share on other sites

(defun c:test ( / list1 list2 whatyouwant) 
  (setq list1 '("a" "b" "c"))
  (setq list2 '("x" "y" "z"))
  
  (defun ex:combinelist ( la lb / lal lbl lo indexa indexb ) 
    (setq lo '())
    (setq lal (length la))
    (setq lbl (length lb))
    (setq indexa 0)
    (repeat lal
      (setq indexb 0)
      (repeat lbl
        (setq lo (cons (list (nth indexa la) (nth indexb lb)) lo))
        (setq indexb (+ indexb 1))
      )
      (setq indexa (+ indexa 1))
    )
    (reverse lo)
  )
  (setq whatyouwant (ex:combinelist list1 list2))
  (princ whatyouwant)
  (princ)
)

 

Edited by exceed
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...