-
-
Save IndhumathyChelliah/2d494af2b65b464957f45aa70ea69bcd 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 | |
selectors=[True,False,True,False] | |
l1=itertools.compress([1,2,3,4],selectors) | |
#Only returns element whose corresponding selector is True. | |
print (list(l1))#Output:[1,3] | |
#filter - instead of passing an iterable of True and False. function is used to determine the value "True or False" | |
l2=filter(lambda x:x%2!=0,[1,2,3,4]) | |
print (list(l2))#Output:[1,3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment