I keep saying that the more programming languages you know, the more you will understand all the others you know - I’m now at the point where I want

These Languages are Accumulating

submited by
Style Pass
2024-11-28 10:00:04

I keep saying that the more programming languages you know, the more you will understand all the others you know - I’m now at the point where I want to solve every problem I see in a handful of different languages. They all offer different functionality, and some are certainly more suited to particular problems than others, but there’s a world of difference between two characters and importing from two libraries.

A newsletter I follow (and can’t find online copies of) that demonstrates neat things in python (gotta learn it, despite not loving it) recently covered accumulate, showing that sum and accumulate were sort of related

Now, firstly… from operator import mul??? It looks like there’s no way to pass * as an argument to a function. I could define a function that performs the same on known arguments, e.g. lambda x, y: x * y

but that requires performing a sum for each sub-interval, so performance would not scale well (admittedly, that was not a consideration here at all). I also don’t believe there’s a built-in prod so one must import math in order to do similar

Leave a Comment