-
-
Save IndhumathyChelliah/34c438ed316a906baa1f5a48cb0c5957 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 filter the elements from the iterable which returns False for the given function | |
l1=itertools.filterfalse(lambda x:x>4,[1,2,3,4,5,6,7,8,9]) | |
print (l1)#Output:<itertools.filterfalse object at 0x0083E658> | |
print (list(l1))#Output:[1, 2, 3,4] | |
#filter() function will filter the elements from the iterable which returns True for the given function | |
l4=filter(lambda x:x>4,[1,2,3,4,5,6,7,8,9]) | |
print (list(l4))#Output:[5, 6, 7, 8, 9] | |
#iterator will filter the elements from the iterable which returns False for the given function | |
l2=itertools.filterfalse(lambda x:x%2==0,[2,4,6,8,10]) | |
print (list(l2))#Output:[] | |
#filter() function will filter the elements from the iterable which returns True for the given function | |
l3=filter(lambda x:x%2==0,[2,4,6,8,10]) | |
print (list(l3))#Output:[2, 4, 6, 8, 10] | |
#If predicate is None, returns the items that are False. | |
l5=itertools.filterfalse(None,[0,1,2,3,4,5]) | |
print (list(l5))#Output:[0] | |
#If predicate is None,filter() function returns the items that are True. | |
l6=filter(None,[0,1,2,3,4]) | |
print (list(l6))#Output:[1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment