Yet another way: (vec (reduce (fn [m [k v]] (assoc m k (+ (m k 0) v))) {} [[1 0.5] [1 0.7] [2 1.0] [3 0.1] [3 0.1]])) => [[3 0.2] [2 1.0] [1 1.2]]
On Friday, March 20, 2015 at 8:45:10 AM UTC-5, Emrehan Tüzün wrote: > > Yet another way to solve it: > > > > > > > > > > > > *user=> x[[1 0.5] [1 0.7] [2 1.0] [3 0.1] [3 0.1]]user=> (group-by first > x){1 [[1 0.5] [1 0.7]], 2 [[2 1.0]], 3 [[3 0.1] [3 0.1]]}user=> (map > #(vector (first %) (second %)) (group-by first x))([1 [[1 0.5] [1 0.7]]] [2 > [[2 1.0]]] [3 [[3 0.1] [3 0.1]]])user=> (map #(vector (first %) (reduce + > (map second (second %)))) (group-by first x))([1 1.2] [2 1.0] [3 0.2])* > > All the best, > Emrehan > > On Thursday, 19 March 2015 23:57:18 UTC+2, Alex wrote: >> >> Hello everybody, >> >> How to transform sequence >> >> *[[1 0.5] [1 0.7] [2 1.0] [3 0.1] [3 0.1]]* >> >> to >> >> *[[1 1.2] [2 1.0] [3 0.2]]* >> >> ? >> >> Best regards, >> Alex >> >> > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.