Map and Filter | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

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
BONGANI INNOCENT MABUZA - avatar
13 Answers
+ 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
OUSSAMA ROMDHANI - avatar
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
David Sebastian Keshvi Illiakis - avatar
0
Wow thanx it worked u are a legend
27th Jun 2017, 6:10 AM
BONGANI INNOCENT MABUZA
BONGANI INNOCENT MABUZA - avatar
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
Michalina Dengusiak - avatar
0
hijos de puta
12th Mar 2019, 11:27 AM
carmenyantonio
carmenyantonio - avatar
0
hi guys
9th May 2019, 7:25 PM
Harman Singh
Harman Singh - avatar
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
GYANENDRA PAL SINGH - avatar
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
Edwin Cancel - avatar
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
makhan Kumbhkar - avatar
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
Madhavareddy
Madhavareddy - avatar
0
1.) Filter 2.) < 3.) nums
30th Dec 2021, 11:31 AM
Thuwayba Ahmed
Thuwayba Ahmed - avatar
0
1.) Filter 2.) lambda 3.) 2
13th Jul 2023, 2:57 PM
Mounir Charif
Mounir Charif - avatar