Python Sort Lamda function - codebugfree

Â There is difference in the python def function and Lamda function. In this Section we will describe the one of the types ofÂ  python function that is lamda. It is same as a def function. But it is use a rare by a programmer. Lamda function is also known as a Anonymous function. It is must use by black white hacker. To make the program like difficult to read able.

Lamda function is types of the one ofÂ  function. Lamda function is the built in function in python. In lamda function support to make in different project Like Blood bank Management. Bank staff Management.

Beginner programmer is confused to use this Lamda function. Because Lamda function is difficult syntax than the Def function. Lot of institute the def function. At las of the python course than teach the lamda function. So they Think it is difficult and why we use if we have the def function.

 Python Lamda function

Most of the hacker know the advantage of this Lamda function and they use their script in Lamda function not a def function. When beginner and intermediate see the scrip than they confuse between th Lamda function. So code bug free is recommand that use also the Lamda function not only the Def function.

Here we will see the some program to How to use the Lamda function. Explain Lamda function code briefly. Now see the code.

``````fuc = lambda a: a+5
mul = lambda x: x*x
sum = lambda b,x,a: b+a+x
x = 5

print(fuc(x))
print(mul(x))
print(sum(x,1,2))``````

Here we create sum multiply Code using the Lamda function. fuc mul and sum is the Lamda function name. a,xb is the function input variable. assign x to 5. Print fuc with 5. print mul with x and sum all three number. I think you does not understand now let see the out of the code

INOUTPUT

``````10
25
8``````

Python Filter and reduce with Lamda function

It is the first project and now see the two more project with filter and reduce python function with using the python lamda function

``````def greaterthan(num):
if num > 5:
return True
else:
return False

g = lambda num: numgrearter thasn10

l = [1,2,34,56,78,34,54,23,12,1,2,3,4]
print(list(filter(greaterthan,l)))
print(list(filter(g,l)))``````

We use two function lamda and def function. This two function show same example. Look the def function it takes the more line of code and the lamda function take only one line. Lamda function is reduce the line of the code.

INOUTPUT

``````[34, 56, 78, 34, 54, 23, 12]
[1, 2, 1, 2, 3, 4]``````

Now see the another example use reduce. Reduce is python function but it is not import in python. does not need to download the pip install reduce. Reduce is built in function so only import the reduce from functools.

``````from functools import reduce
sum = lambda a,b:a+b
l = [1,23,45,23,2,6,7,9,45]
value = reduce(sum,l)
print(value)``````

INOUTPUT

``161``

Reduce is use to sum.