3

The following:

(zipmap '(:a :b :c :c) '(1  2  3  4))

evals to: {:c 4, :b 2, :a 1}

I would like to get:

{:c '(3 4) :b '(2) :a '(1)}

instead.

How should I define my own zipmap that takes two lists and returns a map with multiple values for keys?

4

1 回答 1

5

这会做

(defn zippy [l1 l2]
  (apply merge-with concat (map (fn [a b]{a (list b)}) l1 l2)))
        ;;; ⇒ #'user/zippy

(zippy '(:a :b :c :c) '(1  2  3  4))
        ;;; ⇒ {:c (3 4), :b (2), :a (1)}
于 2013-06-16T16:30:00.073 回答