I have a list of lists and would like to get this into a map where the key is one of the common values in the lists (animal name in this example). I know how to use into {} and for to create a map from a list but this is not exactly what I want. I want the key (animal's name) in the map to refer to a list of lists of these values.
I've created a list of lists
(def animals (list '("tiger" "fur" "yellow & black stripes") '("tiger" "weight" "150") '("tiger" "home" "India") '("elephant" "skin" "gray") '("elephant" "weight" "1500") '("elephant" "home" "Africa") '("frog" "skin" "green") '("frog" "diet" "insects")))
animals
(("tiger" "fur" "yellow & black stripes") ("tiger" "weight" "150") ("tiger" "home" "India") ("elephant" "skin" "gray") ("elephant" "weight" "1500") ("elephant" "home" "Africa") ("frog" "skin" "green") ("frog" "diet" "insects"))
This doesn't do exactly what I want (but almost)
(def animal-map (into {} (for [[name attribute value] animals] [name (list attribute value)])))
This results in only a single list for each key when I want multiple lists for each key
animal-map (map of lists)
{"tiger" ("home" "India"), "elephant" ("home" "Africa"), "frog" ("diet" "insects")}
This is want I want to end up with.
animal-map (map of list of lists)
{"tiger" ("fur" "yellow & black stripes") ("weight" "150") ("home" "India"),
"elephant" ("skin" "gray") ("weight" "1500") ("home" "Africa"),
"frog" ("skin" "green") ("diet" "insects")}