Last active
May 2, 2018 09:07
-
-
Save vehas/4bfdc633de40062c77d4b72fcf531781 to your computer and use it in GitHub Desktop.
swap-sub.clj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def qs {1 [:a :b] 2 [:a] 3 [:b] 4 [:b :c] 5 [:a] 6 [:a :c]}) | |
(defn swap-sub [m] | |
(->> m | |
(mapcat (fn [[k v]] (zipmap v (repeat k)))) | |
(group-by first) | |
(map (fn [[k v]] [k (mapv second v)])) | |
(into {}))) | |
(swap-sub qs) ;=> {:a [1 2 5 6], :b [1 3 4], :c [4 6]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment