+ 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)
13 Respostas
+ 4
res = list (filter(lambda x : x<5, nums))
print (res)
+ 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.
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
0
Wow thanx it worked u are a legend
0
I filtered it but I don't know what to put in between the x's
0
hijos de puta
0
hi guys
0
nums = [1, 2, 5, 8, 3, 0, 7]
res = list(filter(lambda x: x5,nums))
print(res)
0
nums = [1, 2, 5, 8, 3, 0, 7]
res = list (filter (lambda x: x<5, nums))
print(res)
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)
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)
0
1.) Filter
2.) <
3.) nums
0
1.) Filter
2.) lambda
3.) 2