Skip to content

Instantly share code, notes, and snippets.

@vehas
Last active May 2, 2018 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vehas/4bfdc633de40062c77d4b72fcf531781 to your computer and use it in GitHub Desktop.
Save vehas/4bfdc633de40062c77d4b72fcf531781 to your computer and use it in GitHub Desktop.
swap-sub.clj
(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