| Is this better? map(partial(reduce, +), partition(7, 7, daily)) Personally I'd be much much more happy to be using this code than the snippet in the article. In fact, I don't program Python regularly and it did take quite a while to figure out what was going on in the code. weekly = [sum(daily[j:j+7]) for j in range(0, len(daily), 7)] Now if you look back at the top snippet, its just normal function calls, so you can be happy to know what's going on after reading documentation for the names "partition" and "daily". If you don't know what "map", "partial", "reduce" and "+" mean, sure you have to look up their documentation too, but they occur frequently enough that you can remember what they do after that. The Clojure version is much more high level and less likely to introduce bugs. Edit: Oh and it should be said that "sum" is equivalent to partial(reduce, +) so I can now say: map(sum, partition(7, 7, daily)) See? The code is just melting away before your eyes. Also note how I have literally no idea what either of the snippets do but am already happily changing one of them. |