Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 5, 2020
Embed
What would you like to do?
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