A list of lists of the same size, for example:
(def d [["A" "B"] ["A" "C"] ["H" "M"]])
How can it be transformed into a list of sets, each of which is indicated for the indices above:
[#{"A" "H"} #{"B" "C" "M"}]
(map set (apply map vector d))
" (apply map vector) " is what is called "zip" in other languages ββsuch as Python. It calls vector for the first element of each element d , then the second element for each element, etc.
(apply map vector)
vector
d
Then we call set in each of these collections.
set
If the hash set allows duplicate keys, you can use:
(apply map hash-set d)
instead you can do more ugly
(apply map (fn [& s] (set s)) d)
I would suggest the following:
(reduce (fn [sets vals] (map conj sets vals)) (map hash-set (first d)) (rest d))