+ 3

# Map and Filter

fill in the blanks to remove all items that are greater than 4 from the list nums = [1, 2, 5, 8, 3, 0, 7] res = list(filter(lambda x:x_5,__)) print(res)

26th Jun 2017, 2:21 PM
BONGANI INNOCENT MABUZA
+ 4
res = list (filter(lambda x : x<5, nums)) print (res)
9th Aug 2019, 1:03 PM
DARCIO KASHWANTALE NETO
+ 4
Hey friends here is an best example for filter I can give. assume a list name fib = [0,1,1,2,3,5,8,13,21,34,55] Now I want to remove all the even numbers from this list, using filters and lambda function so my code is: result = filter(lambda x: x % 2 == 0, fib) now when I print the result, the output is: print (result) >> [0, 2, 8, 34] This shows that the result is holding all the values that we wanted to remove. Similarly in the given question we want numbers greater than 4 to be removed. so similarly our result will be holding the values which are less than 5 and not greater than 4 so our code will be res = list(filter (lambda x:x <5,nums)) print (res) Here the Best Analogy that you can have is having your own Subset from a Set.
8th Sep 2019, 11:07 PM
OUSSAMA ROMDHANI
0
um u want to remove all items greater than 4, so u filter numbers which are only smaller than 5, and then filter takes two arguments, the function and the list itself
26th Jun 2017, 2:24 PM
David Sebastian Keshvi Illiakis
0
Wow thanx it worked u are a legend
27th Jun 2017, 6:10 AM
BONGANI INNOCENT MABUZA
0
I filtered it but I don't know what to put in between the x's
2nd Nov 2018, 12:17 PM
Michalina Dengusiak
0
hijos de puta
12th Mar 2019, 11:27 AM
carmenyantonio
0
hi guys
9th May 2019, 7:25 PM
Harman Singh
0
nums = [1, 2, 5, 8, 3, 0, 7] res = list(filter(lambda x: x5,nums)) print(res)
3rd Aug 2019, 6:14 AM
GYANENDRA PAL SINGH
0
nums = [1, 2, 5, 8, 3, 0, 7] res = list (filter (lambda x: x<5, nums)) print(res)
7th Oct 2019, 12:29 AM
Edwin Cancel
0
Fill in the blanks to extract all items that are less than 5 from the list. nums = [1, 2, 5, 8, 3, 0, 7] res = list(filter(lambda x: x<5:5,nums)) print(res)
28th Apr 2020, 3:28 AM
makhan Kumbhkar
0
question : Fill in the blanks to extract all items that are less than 5 from the list. program : nums = [1,2,5,8,3,0,7] res = list(filter(lambda x:x<5,nums)) print(nums)
28th May 2021, 11:59 AM