Created
December 8, 2010 18:38
-
-
Save jkk/733691 to your computer and use it in GitHub Desktop.
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
;; in response to https://gist.github.com/733674 | |
(def m | |
{"Lisa Rose" {"Lady in the Water" 2.5 "Snakes on a Plane" 3.5} | |
"Gene Seymour" {"Lady in the Water" 3.0 "Snakes on a Plane" 3.5}}) | |
;; one way | |
(reduce | |
(fn [m [critic movie rating]] | |
(assoc-in m [movie critic] rating)) | |
{} | |
(for [[critic ratings] m | |
[movie rating] ratings] | |
[critic movie rating])) | |
;; another way | |
(reduce | |
(fn [m [critic ratings]] | |
(reduce | |
(fn [m [movie rating]] | |
(assoc-in m [movie critic] rating)) | |
m ratings)) | |
{} m) | |
;; yet another way | |
(apply | |
merge-with merge | |
(for [[critic ratings] m | |
[movie rating] ratings] | |
{movie {critic rating}})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment