ModularM
Modularβ€’2y agoβ€’
12 replies
seboll13

Easier way to sum a list of integers

Hello there, I'm trying to learn Mojo by creating some small simple programs and comparing them to Python to learn key differences. I've joined an example of the last function I wrote in my code.

In this specific case, get_unbiased_run returns an integer value and the goal of this function is to sum the value of all runs. In Python, one would do a simple one liner by summing all elements of a generator. I don't know what the equivalent would be in mojo and believe this code can be optimised. I've noticed the existence of Buffers and the "sum" function from the algorithm module but not sure how I could make it work here. Any help is welcomed !

Thanks in advance πŸ™‚
Screenshot_2024-04-11_at_19.39.02.png
Was this page helpful?