swap keys and values in a map

后端 未结 4 1056
忘掉有多难
忘掉有多难 2021-02-19 01:47

Is there a function to swap the key and value of a given map. So given a map, I want the keys to become values, and values the keys.

(swap {:a 2 b 4}) => {2 :         


        
4条回答
  •  旧巷少年郎
    2021-02-19 02:01

    This is the purpose of map-invert in clojure.set:

    user=> (clojure.set/map-invert {:a 2 :b 4})
    {4 :b, 2 :a}
    

提交回复
热议问题