This is from the book I'm reading:
We’ll start with an example. Suppose we have a list L:Two immediate observations:1> L = [1,2,3,4,5].And suppose we want to double every element in the list. We’ve done this before, but I’ll remind you:
[1,2,3,4,5]2> lists:map(fun(X) -> 2*X end, L).But there’s a much easier way that uses a list comprehension:
[2,4,6,8,10]4> [2*X || X <- L ].The notation [ F(X) || X <- L] means “the list of F(X) where X is taken from the list L.” Thus, [2*X || X <- L ] means “the list of 2*X where X is taken from the list L.”
- Python, this ain't.
- My god, you have to read it right-to-left to follow the logic. Who thought that was a good idea?
Leaving for British Columbia tomorrow to spend the holidays with my wife's extended family (sharing a small house with two infants included). Wish me lots of patience. ;)