l()
What does l() do?
l() is another loop that returns a singular value instead of an array like how eK() does. It uses a and b to denote the cumulative value and the next value to add respectively. For example, l(a+b) will sum the values of x, so [1, 2, 3] becomes 6.
from ArrayExpressions import arrex
lst = [1, 2, 3, 4, 5]
output = arrex.evaluate(lst, "l(a+b)")
print(output) # 15
When the loop first starts, a takes on i0(x) and b takes on i1(0). After, a is whatever value was returned by the last iteration and b is the next value in x. For example, l() can be used to find the max in x by comparing a (the highest value found so far) to b (the next value in x).
from ArrayExpressions import arrex
lst = [1, 3, 2, 7, 5]
output = arrex.evaluate(lst, "l(b > a ? b : a)")
print(output) # 7
Other Important Information:
Input | Any valid ArrEx code that returns a value. It is highly reccommended that a and b are in the input. |
---|---|
Does it create a new scope? | No for x, but a and b take on new values. |
Output | A singular value that is the cumulation of every element in x |
K | Nonw |
I | Iteration starting at 0 |
Example | l(a*b) |
Example Explanation | This multiplies the values of x together to get the product. |