Hi folks Do you know what is wrong with the code below? m=[x for x in range(1,16)] threes_and_fives=filter(lambda x:if x%3==0 or x%5==0,m)
in this exercise , i think no need for filter and lambda ; create a list, threes_and_fives, that consists only of the numbers between 1 and 15 (inclusive) that are evenly divisible by 3 or 5.
Yes,I did it as you say and was correct. but I want to know that what is the problem with this way?
the code is tested against a certain test. Good solutions may fail to pass the test
threes_and_fives = [x for x in range(1,16) if (x % 3 == 0) or (x % 5 == 0)]
is one line of code, single function and provides the expected result,
using a "lambda filter" on a "list comprehension" provides the same result but do non pass the testing formula