Please Help me add up the elements for this structure in Scheme/Lisp

Posted by kunjaan on Stack Overflow See other posts from Stack Overflow or by kunjaan
Published on 2009-07-11T21:13:01Z Indexed on 2010/05/18 15:51 UTC
Read the original article Hit count: 305

I have an input which is of this form:

(((lady-in-water . 1.25) (snake . 1.75) (run . 2.25) (just-my-luck . 1.5))
 ((lady-in-water . 0.8235294117647058) (snake . 0.5882352941176471) (just-my-luck . 0.8235294117647058))
 ((lady-in-water . 0.8888888888888888) (snake . 1.5555555555555554) (just-my-luck . 1.3333333333333333)))

(context: the word denotes a movie and the number denotes the weighted rating submitted by the user)

I need to add all the quantity and return a list which looks something like this

((lady-in-water 2.5)
 (snake 2.5)
 (run   2.25)
 (just-myluck 2.6))

How do I traverse the list and all the quantities? I am really stumped. Please help me.

Thanks.

© Stack Overflow or respective owner

Related posts about Scheme

Related posts about lisp