I'm a C# developer looking to learn more about Python and how to think in a more functional programming manner.I have the following which takes a series of grades and returns the average:grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]def grades_sum(scores):    total = 0    for score in scores:        total += score    return totaldef grades_average(grades):    return grades_sum(grades) / float(len(grades))print(grades_average(grades))What are some better functional programming / pythonic ways of approaching this problem?
Calculating average grades
python;performance;functional programming
For the sake of the review, let us ignore the fact that there is both a sum (from Python 2.3) and statistics.mean (from Python v3.4), and analyse your code:Good style in general  You seem to be following PEP8, and that is goodSome bad names  Read out stuff like grades_sum(grades), it reads like do the grades sum of grades. What is a grades sum versus an ordinary sum? On the other hand sum(grades) reads similarily as do the sum of grades. It has a natural flow, which we want to aim for. In addition when looking at the function it doesn't care whether we're adding grades or whatever else which can be added togetherOK, code of functions  Nothing really magic happens in either function. They are straight forward, and you don't do anything extra (with exception of ignoring the predefined sum and mean. Not to many variable, and the concern for each function is clearBe wary of the / divider in Python 2.x  This operator is somewhat unclear in Python 2.x, as it can be using integer division (and floor'ing the result) or change the end result into a float. See PEP238 for full discussion, but if you want true division when using / (i.e. to get float results consistently (if I've understood it correctly)) use from __future__ import division, and use // when you want the division floor'ed. Alternative do as you did, use float(divisor) to force it to become a floatGood print, but can be better It is to easy to just print numbers in code, which you at some point will wonder: What was that number?. It's better to get used to a good code template like: print('Average of grades: {:,.2f}'.format(grades_average(grades)) or similar. This prints your value with a leading text, and let the float argument be printed with 2 decimalsWhen all this is said and done, read the documentation or do searches like python sum or python mean before reinventing the wheel. 