List Comprehension Bug

List_Comprehension_Bug

When I used list comprehension in a function, Desmos thought that I wanted to iterate over a number, and gave an error. However, I was iterating over a list. I attached an image of this described behavior above.

I can see how this feels “buggy”, but this is a known limitation of list comprehension. Moving this to the questions category so that you can get some help from the forum.

Because variables can hold all sorts of math “things” — numbers, functions, lists of numbers, parametric expressions, etc. — when you define a(b) there’s no way for the calculator to know you intend to use b like a list! So, it throws an error; even though you call the function in line 2 with a list input, the error exists in the definition of the function, so it can’t be evaluated.

There is a way to define your function, though! If you join with an empty list, the list comprehension will always see a list on the other side of that equals sign. Check it out here: https://www.desmos.com/calculator/6rjaw6bhcj

1 Like

Thanks for the help! I also found another fix while playing with Desmos:

Desmos recognizes “b” as a list, if you define the range of it.

Oh fascinating, I did not expect that!