return reduce(lambda x, y: x.grade+y.grade, self.reviews)

cnb circularfunc at yahoo.se
Fri Aug 29 19:54:32 CEST 2008


class Customer(object):
    def __init__(self, idnumber, review):
        self.idnumber = idnumber
        self.reviews = [review]

    def addReview(self, review):
        self.reviews.append(review)

    def averageGrade(self):
        tot = 0
        for review in self.reviews:
            tot += review.grade
        return tot / len(self.reviews)

    def av_grade(self):
        return reduce(lambda x, y: x.grade+y.grade, self.reviews)


now,the function is pointless and incorrect but av_grade doesn't work.
why can't i use reduce like this?



More information about the Python-list mailing list