Thursday, November 14, 2019

Learning Python- Day 10


DAY 10

def cube(x):
   
return x*x*x
n=
int(input("Enter a number "))
print(cube(n))
run the function CTL+shift+fn+F10
Enter a number 5
125
Now we use lambda
cube=lambda x:x*x*x
n=
int(input("Enter a number "))
print(cube(n))
run the function CTL+shift+fn+F10
Enter a number 5
125
list1=["11","22","33","44","55"]
list2=
list(map(int,list1))
print(list2)
run the function CTL+shift+fn+F10
[11, 22, 33, 44, 55]
def cube(x):
   
return x*x*x

list1=[
1,2,3,4,5]
list2=
list(map(cube,list1))
print(list2)
run the function CTL+shift+fn+F10
[1, 8, 27, 64, 125]
l1=[10,20,30,40,50]
l2=
list(map(lambda x:x*x,l1))
print(l2)
run the function CTL+shift+fn+F10
[100, 400, 900, 1600, 2500]

def is_greater(x):
    if(x>5):
        return x


list1=[1,2,3,4,5,6,7,8,10]
list2=list(filter(is_greater,list1))
print(list2)

run the function CTL+shift+fn+F10
[6, 7, 8, 10]
l1=[10,30,40,20,12,23,12,11]
l2=
list(filter(lambda x:x>20,l1))
print(l2)


For reduce

from functools import reduce

l1=[
10,20,30,40,50]
n=reduce(
lambda x,y:x+y,l1)
print(n)
run the function CTL+shift+fn+F10
150

No comments:

Post a Comment

Featured Post

Ichimoku cloud

Here how you read a ichimoku cloud 1) Blue Converse line: It measures short term trend. it also shows minor support or resistance. Its ve...