List comprehension tips
If you are unaware, a new feature has been released in Desmos a few months ago: list comprehensions
They are similar to Python list comprehensions, where you can essentially use loops to construct lists. This functionality now allows us to be able to emulate nested for loops in Desmos, which was previously much harder to do.
List comprehensions follow the below form:
[(expression in terms of var1, ... ,varN) for var1 = (list1), var2 = (list2), ... , varN = (listN)]
This will construct a list by looping through each
var1, var2, ... , varN in a nested fashion.
There are some golfs you can do to save bytes in list comprehensions.
Let's take a simple list comprehension below:
Like any other function, you can simply take out the
\operatorname from the
for and it will still work. So all in all, you have something like this:
Even though the
a are together, Desmos will still be able to distinguish between them.
A quirk with list comprehensions (and nested for loops in general) is that you will actually get different lists based on the order of each list. Here's an example to illustrate my point (obviously not golfed completely for readability):
[a+b for a = [1,2,3], b = [2,4,6]] --> [3,4,5,5,6,7,7,8,9]
[a+b for a = [2,4,6], b = [1,2,3]] --> [3,5,7,4,6,8,5,7,9]
Generally, a list comprehension is generated following the pseudocode below (using the general list comprehension form that I mentioned earlier):
SET result to empty list
FOR each varN in (listN)
FOR each var2 in (list2)
FOR each var1 in (list1)
ADD (expression in terms of var1, ... , varN) to the end of result
A certain ordering of the lists can potentially save a few bytes over another if a code golf challenge requires the list output to be ordered in a certain way.