-
-
Save IndhumathyChelliah/d4a5b1873b5a5b41a6810e88c71e1dfe 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 | |
l1=itertools.starmap(pow,[(0,2),(1,2),(2,2)]) | |
print (l1)#Output:<itertools.starmap object at 0x00C8E4D8> | |
#We can iterate through starmap object,using for loop or using next() function. We can also convert to list object. | |
print (list(l1))#Output:[0, 1, 4] | |
#using map() | |
l2=map(pow,[0,1,2],[2,2,2]) | |
print (list(l2))#Output:[0, 1, 4] | |
a1=map(lambda x:x**2,[1,2,3]) | |
print (list(a1))#Output:[1, 4, 9] | |
#If elements inside the iterable are not iterable, it will raise TypeError. | |
a2=itertools.starmap(lambda x:x**2,[1,2,3]) | |
print (list(a2))#Output:TypeError: 'int' object is not iterable | |
a3=itertools.starmap(lambda x,y:x+y,[(0,1),(1,2),(2,3)]) | |
print (list(a3))#Output:[1, 3, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment