3

If I have two arbitrary length lists of the same [arbitrary] length, X and Y, how do I merge them such that

((X1 Y1) (X2 Y2) ... (Xn Yn)) ?

e.g. List X: (1 3 4 5 6 ... N) and List Y: (5 13 1 4 9 ... N)

how do I merge them to create something like

((1 5) (3 13) (4 1) (5 4) (6 9) ... ) ?

mikera
  • 105,238
  • 25
  • 256
  • 415
  • 1
    possible duplicate of [Is there an equivalent for the Zip function in Clojure Core or Contrib?](http://stackoverflow.com/questions/2588227/is-there-an-equivalent-for-the-zip-function-in-clojure-core-or-contrib) – Don Roby Jul 09 '12 at 11:23
  • 2
    Not really a duplicate - it's a different context and co-ordinates are different from zipped pairs in various interesting ways – mikera Jul 09 '12 at 11:36
  • 1
    In what way is it different? It looks exactly the same to me. – amalloy Jul 09 '12 at 18:18

1 Answers1

7
(map list [1 2 3] [4 5 6])
=> ((1 4) (2 5) (3 6))

Though for coordinates, I'd use (map vector ...) instead:

(map vector [1 2 3] [4 5 6])
=> ([1 4] [2 5] [3 6])
Joost Diepenmaat
  • 17,633
  • 3
  • 44
  • 53
  • can you explain why you prefer vector for coordinates? – Jeff Johnston Jul 13 '12 at 21:32
  • 1
    I would prefer vectors for this, because I personally like `(v 0)` and `(v 1)` notation for accessing the X and Y components directly from the vector, which is useful in short expressions. The alternatives with lists/seqs are less appealing. – Joost Diepenmaat Jul 16 '12 at 07:11