Can someone explain?


languages = ["HTML", "JavaScript", "Python", "Ruby"]
print filter(_______, _______)

didnt understand both the Lambda concept and how to solve this exercise. someone plz help me


lambda is a function. lets look at the example:

my_list = range(16)
filter(lambda x: x % 3 == 0, my_list)

so filter has two parts:

filter(function, iterable)

see docs, so the iterable is our list (languages, my_list in the example)

which leaves us with the function part of filter, for which we are going to use lambda.

lets start with lambda x:, it looks very much like a function, doesn't it? look:

def example(x):

by using lambda we can leave out the def keyword and the parentheses

lets continue building our function:

def example(x):
    x % 3 == 0

so x % 3 == 0 is our function content. Here filter() comes in again, if this condition evaluates to true, filter will add it to our list


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.