Answers for "takewhile iterator"

0

takewhile iterator

# Python code to demonstrate the working of 
# takewhile()
   
 
import itertools
   
# initializing list 
li = [2, 4, 6, 7, 8, 10, 20]
   
# using takewhile() to print values till condition is false.
print ("The list values till 1st false value are : ", end ="")
print (list(itertools.takewhile(lambda x : x % 2 == 0, li )))
Posted by: Guest on August-10-2021

Python Answers by Framework

Browse Popular Code Answers by Language