Featured Post

Set up machine learning and deep learning on AWS

Here is the simple instructions to set up a EC2 instance to run machine learning and deep learning on AWS 1.  Run an EC2 instance from ...

Apr 24, 2020

Python map and filter function

Python provides map and filter functions to process computations on the list of items. Here is a list of examples how to use map and filter.

Python map function examples

Compute the square of 1 to 10

def f(x):
    return x*x

map(f, range(1, 11))

or use lambda functions

map(lambda x: x*x, range(10)) 


Python filter function examples

Extract the event numbers from 1 to 10

def f(x):
    return x%2 == 0

filter(f, range(1, 11))

or use lambda functions

filter(lambda x: x%2 == 0, range(1, 11))

0 comments:

Post a Comment