+ 5
[Solved] be careful of returning 0 to filter() function.
Please look at these two codes: 1ď¸âŁ First code: def mulof3(x): if x % 3 == 0: return x m3 = list(filter(mulof3,range(10))) print(m3) #Outputs: [3,6,9] 2ď¸âŁ Second code: (same task with lambda function) m3 = list(filter(lambda n: n%3==0, range(10))) print(m3) #Outputs: [0,3,6,9] đ Question: I can't understand why the first one doesn't output 0 in the list? Aren't these two codes the same?
3 Answers