+ 1

Why we give these 3 values inside filter? What is the syntax of filter?

nums = [11, 22, 33, 44, 55] res = list(filter(lambda x: x%2==0, nums)) print(res)

24th Jul 2018, 2:07 PM
ADITYA SINHA
ADITYA SINHA - avatar
2 Respostas
0
filter, as well as map, takes 2 arguments. The first one is the function to be applied to the list. The second one is the list itself. The result has to be converted into a list with the list function. The function can either be already declared elsewhere in the code or be anonymous. Anonymous functions are declared using the lambda keyword. Here are the related lessons: https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2460/ https://www.sololearn.com/learn/Python/2461/
24th Jul 2018, 2:43 PM
giannismach
giannismach - avatar
- 1
it's a filter basically just filters out all list members that do not meet the lambda condition
24th Jul 2018, 2:40 PM
hinanawi
hinanawi - avatar