Here’s an example of an list comprehension in Haskell from Wikipedia:
a = [(x,y) | x <- [1..5], y <- [3..5]]
-- [(1,3),(1,4),(1,5),(2,3),(2,4) ...
In this example, a list of pair of integers is constructed from 2 lists of integers.
Here is what that example would be in Python:
a = [(x, y) for x in range(1,6) for y in range(3, 6)]
# [(1, 3), (1, 4), (1, 5), (2, 3), (2, 4) ...
Here’s what it would be in mathematics (except we are dealing with sets, not lists, but I’ll only refer to lists from here on.):
Let (a, b) be an ordered list of elements
{(x, y)|x ∈ {1,2,3,4,5}, y ∈ {3,4,5}}
One can filter out unwanted elements with predicates, and apply arbitrary functions to elements of the result. Let’s say we only want even numbers from the first list, and we want the sum of x and y, continuing on our examples:
a = [x+y | x <- [1..5], y <- [3..5], x `mod` 2 == 0]
a = [x + y for x in range(1,6) for y in range(3, 6) if x % 2 == 0]
{x+y|x ∈ {1,2,3,4,5}, y ∈ {3,4,5}, x is even}