Skip to content

Instantly share code, notes, and snippets.

Last active Jul 6, 2020
What would you like to do?
import itertools
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()
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