Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 5, 2020 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/2d494af2b65b464957f45aa70ea69bcd to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/2d494af2b65b464957f45aa70ea69bcd to your computer and use it in GitHub Desktop.
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