Python map-reduce-filter
Jump to navigation
Jump to search
Map, Reduce and Filter
- Map: applies a function to each value of an iterable, with basic syntax: map(function, iterable).
<syntax
def square(x):
return x*x
mynums = [17, 10, 3, 1, 5, 14, 15, 10, 6, 12]
result = map(square, mynums)
# or
result = map(lambda x: x*x, mynums)
# output
list(result)
[289, 100, 9, 1, 25, 196, 225, 100, 36, 144]