创建哈希映射 Clojure
Creating Hash-Map Clojure
我有 2 个列表,比如说用户列表 (list-usr) 和 (usr-index),我想从这些列表中创建哈希映射,就像
(def list-usr [196 186 244])
(def idx-usr [0 1 2])
我如何从 2 个列表中形成 (hash-map {196 0 186 1 244 2})
?
拜恩贾蒂
取两个向量交错创建hash map的函数是zipmap.
它应该提供您想要的内容,请记住您将使用整数作为键:
(zipmap list-usr idx-usr)
我有 2 个列表,比如说用户列表 (list-usr) 和 (usr-index),我想从这些列表中创建哈希映射,就像
(def list-usr [196 186 244])
(def idx-usr [0 1 2])
我如何从 2 个列表中形成 (hash-map {196 0 186 1 244 2})
?
拜恩贾蒂
取两个向量交错创建hash map的函数是zipmap.
它应该提供您想要的内容,请记住您将使用整数作为键:
(zipmap list-usr idx-usr)