[Solved] be careful of returning 0 to filter() function. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

4th Mar 2022, 10:41 AM
Siavash Kardar Tehran
Siavash Kardar Tehran - avatar
0 Answers