Anonymous user
Apply a callback to an array: Difference between revisions
+python
(c++ stl for_each example) |
(+python) |
||
Line 84:
}
//prints 1x 2x 3x 4x 5x
== Python ==
def square(n):
return n * n
numbers = [1, 3, 5, 7]
squares1 = [square(n) for n in numbers] # list comprehension
squares2 = map(square, numbers)
|