5. List comprehensions Flashcards

1
Q

Describe the syntax of a comprehension

A

> [x^2 | x <- [1..5], x mod 2 == 0]
x^2 is the result format
x <- says x is drawn from within a specific range
x mod 2 == 0 is the guard of the comprehension

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to produce a new list by pairing successive elements?

A

> zip [‘a’, ‘b’, ‘c’] [1,2,3]
[(‘a’, 1), (‘b’, 2), (‘c’, 3)]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly