+ 2
% Operation
I don't know why the out put is [], could anyone tells me? Thanks! https://code.sololearn.com/cAl8Ac0qcMUI/?ref=app
2 odpowiedzi
+ 1
https://docs.python.org/3/library/itertools.html#itertools.takewhile
In the implementation you can see 2 things....
- It’s a generator so
for i in takewhile(...):
print(i)
- The generator stops when a condition is false (the else: break part)
Use filter instead which is built in...
print(list(filter(lambda x: x % 2 == 0, nums)))
0
TurtleShell Thank you very much, I got it