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

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes