+ 1
Fill in the blanks to take the numbers from the list while they are even, using the takewhile function. from itertools t
ss
6 Réponses
+ 5
from itertools import takewhile
nums = [2, 4, 6, 7, 9, 8]
a = takewhile(lambda x: x%2==0, nums)
print(list(a))
+ 2
from itertools import takewhile
nums = [2,4,8,7,2,3,6]
print(list(takewhile(lambda x: x % 2 == 0, nums)))
Output:
[2,4,8]
The list nums contains the numbers that you want. I just put random numbers.
0
from itertools import takewhile
nums = [2, 4, 6, 7, 9, 8]
a = takewhile(lambda x: x%2==0, nums)
print(list(a))
0
Fill in the blanks to take the numbers from the list while they are even, using the takewhile function.
from itertools
import
takewhile
nums = [2, 4, 6, 7, 9, 8]
a =
takewhile
(
lambda
x: x%2==0, nums)
print(list(a))
0
Fill in the blanks to take the numbers from the list while they are even, using the takewhile function.
answer : from itertools import takewhile
nums = [2,4,6,7,9,8]
a = takewhile(lambda x:x%2==0,nums)
print(list(a))
0
Answer:
from itertools import takewhile
nums = [2,4,6,7,9,8]
a = takewhile(lambda x:x%2==0,nums)
print(list(a))