Which is faster?

cnb circularfunc at yahoo.se
Sat Aug 30 06:26:35 CEST 2008

For a big nbr of it might matter?
Is av_grade O(n*2) and the first O(n)  when it comes to adding or is
"sum x for x in y" just traversing the list ones, accumulating the
values, it doesnt first build the list and then travese it for sum?

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

def av_grade(self):
     return sum(review.grade for review in self.reviews) / \

More information about the Python-list mailing list