下列:
(zipmap '(:a :b :c :c) '(1 2 3 4))
Run Code Online (Sandbox Code Playgroud)
逃避: {:c 4, :b 2, :a 1}
我想得到:
{:c '(3 4) :b '(2) :a '(1)}
Run Code Online (Sandbox Code Playgroud)
代替.
我应该如何定义自己的zipmap两个列表并返回一个具有多个键值的映射?
首先,我是The Iron Yard 12周5中的学生,学习Java后端工程.该课程由大约60%的Java,25%的JavaScript和15%的Clojure组成.
我收到了以下问题(在评论中概述):
;; Given an ArrayList of words, return a HashMap> containing a keys for every
;; word's first letter. The value for the key will be an ArrayList of all
;; words in the list that start with that letter. An empty string has no first
;; letter so don't add a key for it.
(defn index-words [word-list]
(loop [word (first word-list)
index {}]
(if (contains? index (subs word 0 1))
(assoc index (subs word 0 …Run Code Online (Sandbox Code Playgroud) 我是Clojure的新手,我需要这个功能的帮助.如果你能告诉我这个功能是做什么的,它是如何工作的,我真的很感激.
(defn zip-map
[k v]
(into{} (map vec (partition 2 (interleave k v)))))
Run Code Online (Sandbox Code Playgroud) 我得到了两个向量[shoes milk shoes]和[1 3 1],而我想要得到的地图是{shoes 2, milk 3}。我尝试了zipmap两个向量并且只{shoes 1 milk 3}显示。没有循环和迭代,还有另一种方法吗?