[Solved] be careful of returning 0 to filter() function. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Resposta