Is there an equivalent for the Zip function in Clojure Core or Contrib?

后端 未结 7 1920
野性不改
野性不改 2020-12-12 20:13

In Clojure, I want to combine two lists to give a list of pairs,

> (zip \'(1 2 3) \'(4 5 6))  
((1 4) (2 5) (3 6))

In Haskell or Ruby t

7条回答
  •  情深已故
    2020-12-12 20:38

    #(apply map list %) transposes a matrix just like the Python zip* function. As a macro definition:

    user=> (defmacro py-zip [lst] `(apply map list ~lst))

    #'user/py-zip

    user=> (py-zip '((1 2 3 4) (9 9 9 9) (5 6 7 8)))

    ((1 9 5) (2 9 6) (3 9 7) (4 9 8))

    user=> (py-zip '((1 9 5) (2 9 6) (3 9 7) (4 9 8)))

    ((1 2 3 4) (9 9 9 9) (5 6 7 8))

提交回复
热议问题