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)))




Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

What is the difference between iostream and iostream.h in cpp?

The Basic Structure of a Full-Stack Web App