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

Using insertAdjacentHTML instead of innerHTML to avoid XSS attacks

Guess The Number Game - You vs. Your Friend