mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
add comprehension filter example
This commit is contained in:
parent
883fe07410
commit
55d4030e97
@ -506,9 +506,10 @@ add_10(3) # => 13
|
|||||||
map(add_10, [1,2,3]) # => [11, 12, 13]
|
map(add_10, [1,2,3]) # => [11, 12, 13]
|
||||||
filter(x -> x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
|
filter(x -> x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
|
||||||
|
|
||||||
# We can use list comprehensions for nicer maps
|
# We can use list comprehensions
|
||||||
[add_10(i) for i=[1, 2, 3]] # => [11, 12, 13]
|
[add_10(i) for i=[1, 2, 3]] # => [11, 12, 13]
|
||||||
[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
|
[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
|
||||||
|
[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7]
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
## 5. Types
|
## 5. Types
|
||||||
|
Loading…
Reference in New Issue
Block a user