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 🙂
您好,我正在尝试通过创建一些简单的小程序并将它们与 Python 进行比较来了解关键差异来学习 Mojo 。我加入了我在代码中编写的最后一个函数的示例。
在这种特定情况下,get _unbiased _run 返回一个整数值,该函数的目标是对所有运行的值求和。在 Python 中,人们可以通过对生成器的所有元素求和来完成一个简单的线性运算。我不知道 mojo 中的等价物是什么,并且相信该代码可以优化。我注意到算法模块中缓冲区和“求和”函数的存在,但不确定如何让它在这里工作。欢迎任何帮助!