-
-
Save IndhumathyChelliah/686e365562a89ccd22f341612a8f3ccf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
##iterator will start displaying after condition is False. | |
l1=itertools.dropwhile(lambda x:x>4,[5,6,7,8,9,1,2,3]) | |
print (l1)#Output:<itertools.dropwhile object at 0x02E592C8> | |
print (list(l1))#Output:[1, 2, 3] | |
#iterator used to print values till condition is False. | |
l4=itertools.takewhile(lambda x:x>4,[5,6,7,8,9,1,2,3]) | |
print (list(l4))#Output:[5, 6, 7, 8, 9] | |
#iterator will start displaying after condition is False. | |
l2=itertools.dropwhile(lambda x:x%2==0,[2,4,6,8,10]) | |
print (list(l2))#Output:[] | |
#iterator used to print values till condition is False. | |
l3=itertools.takewhile(lambda x:x%2==0,[2,4,6,8,10]) | |
print (list(l3))#Output:[2, 4, 6, 8, 10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment