Applying a function to a list by MAP method
Syntax:
map(function, list)
def cube(num):
return num*num*num
# method 01
l1 = [2, 4, 6]
l2 = []
for item in l1:
l2.append(cube(item))
print(l2)
# method 02
print(list(map(cube, l1)))
Syntax:
map(function, list)
Comments
Post a Comment
Write something to CodeWithAbdur!