reversing hash map in clojure
clojure, data-structures, hashmap
Solution
(def m {"key1" "value1" "key2" "value2" "key3" "value1"})
(let [g (group-by val m)
vals (map #(map first %) (vals g))]
(zipmap (keys g) vals))
;;=> {"value2" ("key2"), "value1" ("key1" "key3")}
Problem
I've hash-map in clojure: ``` {"key1" "value1"} {"key2" "value2"} {"key3" "value1"} ``` and i need to convert it into hash map of ``` {"value1" {"key1" "key3"}} {"value2" {"key2"}} ``` Any clojure way of doing this? clojure.set/map-invert will not work as if it overrides repeated values.