triplej
triplej

Reputation: 299

How do I sum the inner sequence in a list of lists?

I want to take a sequence of sequences and sum up each inner sequence.

Data ((1 2 3) (2 3 4) (3 4 5) (4 5 6))

Desired output ((6) (9) (12) (15)) or (6 9 12 15)

I've tried apply map + which doesn't give the desired output. I've also experimented with reduce.

Upvotes: 0

Views: 151

Answers (1)

Rulle
Rulle

Reputation: 4901

(map #(apply + %) '((1 2 3) (2 3 4) (3 4 5) (4 5 6)))
;; => (6 9 12 15)

(map #(list (apply + %)) '((1 2 3) (2 3 4) (3 4 5) (4 5 6)))
;; => ((6) (9) (12) (15))

Upvotes: 2

Related Questions