SlideShare a Scribd company logo
RECURSION AND LAMBDA FUNCTIONS
VINAY AGRAWAL
ASST. PROFESSOR
CEA DEPT.
GLA UNIVERSITY,
MATHURA
Recursion
Tower of Hanoi Problem
Recursion and Lambda Functions in python.ppt
def toh(source,destination,aux,n):
if n>=1:
toh(source,aux,destination,n-1)
print("Move",source,"to",destination)
toh(aux,destination,source,n-1)
toh('A','B','C',3)
Programs
1. WAP to find the factorial of a number provided
by user using Recursion.
2. WAP to print the fibonacci Series upto n terms,
where n is provided by user.
3. WAP to find the GCD (or HCF) using Recursion.
4. WAP to input a string from the user and check
whether it is palindrome or not.
Lambda Functions or Anonymous Functions
 Those Functions which does not have any name is called
Anonymous Functions. In Python, this can be achieved by using
keyword lambda, that’s why it is also called Lambda Functions.
 They are not declared in the standard manner by using the def
keyword
 Lambda forms can take any number of arguments but return
just one value in the form of an expression. They cannot
contain commands or multiple expressions.
Syntax
 The syntax of lambda functions contains only a single
statement, which is as follows:
lambda arg1 ,arg2,.....argn:expression
Example:
add = lambda a, b : a + b
print("Value of total : ", add( 10, 20 ) )
Non-Anonymous Function Anonymous Function
def square(x):
return x*x
n=int(input(“Enter the Number”))
print(square(n))
a=lambda x:x*x
n=int(input(“Enter the Number”))
print(a(n))
Lambda Function with map() function
l=list(map(int,input().split()))
Similarly
L1=[1,2,3,4]
L2=list(map(lambda x:x*x,L1))
print(L2)
Output:[1,4,9,16]
Lambda Function with filter() function
L1=[1,2,3,4]
L2=list(filter(lambda x:x%2==0,L1))
print(L2)
Output:[2,4]
Lambda Function with reduce() function
import functools
L1=[1,2,3,4,5,6,7,8,9,10]
L2=functools.reduce((lambda a , b : a+b), L1)
print(L2)
Output:55

More Related Content

PDF
Deriving the Y Combinator
PPTX
Python lambda.pptx
PDF
What is Python Lambda Function? Python Tutorial | Edureka
PPTX
Recursion vs. Iteration: Code Efficiency & Structure
PPTX
Python Lambda Function
PPTX
Introductions to Functions in python programming.pptx
PPTX
LambdaFunctionsLambdaFunctions.LambdaFun
PPTX
functions.pptx
Deriving the Y Combinator
Python lambda.pptx
What is Python Lambda Function? Python Tutorial | Edureka
Recursion vs. Iteration: Code Efficiency & Structure
Python Lambda Function
Introductions to Functions in python programming.pptx
LambdaFunctionsLambdaFunctions.LambdaFun
functions.pptx

Similar to Recursion and Lambda Functions in python.ppt (20)

PPTX
Advance Programming Slide lecture 4.pptx
PDF
Python lambda functions with filter, map & reduce function
PPT
04_python_functions.ppt You can define functions to provide the required func...
PPTX
Advance python programming
PDF
Y-Combinator In Scheme, Recursion in Lambda Calcul
PPTX
Python for Data Science function third module ppt.pptx
PPTX
Function in Python.pptx by Faculty at gla university in mathura uttar pradesh
PPTX
Chapter 02 functions -class xii
PPT
14 recursion
PPTX
UNIT-02-pythonfunctions python function using detehdjsjehhdjejdhdjdjdjddjdhdhhd
PPTX
_Python_ Functions _and_ Libraries_.pptx
PPTX
Python Session - 4
PPTX
Full_Fixed_Enhanced_Recursion_Presentation.pptx
PPTX
Lambda Calculus
PPT
recursion.ppt
PPTX
Function & Recursion
PPTX
Functions in python, types of functions in python
PPSX
python Function
PPTX
lambda engineering students machine learnings.pptx
PPTX
35000120060_Nitesh Modi_CSE Presentation on recursion.pptx
Advance Programming Slide lecture 4.pptx
Python lambda functions with filter, map & reduce function
04_python_functions.ppt You can define functions to provide the required func...
Advance python programming
Y-Combinator In Scheme, Recursion in Lambda Calcul
Python for Data Science function third module ppt.pptx
Function in Python.pptx by Faculty at gla university in mathura uttar pradesh
Chapter 02 functions -class xii
14 recursion
UNIT-02-pythonfunctions python function using detehdjsjehhdjejdhdjdjdjddjdhdhhd
_Python_ Functions _and_ Libraries_.pptx
Python Session - 4
Full_Fixed_Enhanced_Recursion_Presentation.pptx
Lambda Calculus
recursion.ppt
Function & Recursion
Functions in python, types of functions in python
python Function
lambda engineering students machine learnings.pptx
35000120060_Nitesh Modi_CSE Presentation on recursion.pptx
Ad

More from vinayagrawal71 (8)

PPT
Sets in the python programming language.ppt
PPT
File Handling in python programming .ppt
PPTX
Exceptional Handling in the python .pptx
PPTX
Exception Handling in Python programming.pptx
PPT
Dictionarys in python programming language.ppt
PPTX
11Exceptional Handling In Python Language.pptx
PPT
File Handling in Python Programming .ppt
PPTX
Exception Handling in Python Programming.pptx
Sets in the python programming language.ppt
File Handling in python programming .ppt
Exceptional Handling in the python .pptx
Exception Handling in Python programming.pptx
Dictionarys in python programming language.ppt
11Exceptional Handling In Python Language.pptx
File Handling in Python Programming .ppt
Exception Handling in Python Programming.pptx
Ad

Recently uploaded (20)

PDF
Queuing formulas to evaluate throughputs and servers
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPT
Chapter 6 Design in software Engineeing.ppt
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PPTX
Internship_Presentation_Final engineering.pptx
PPTX
anatomy of limbus and anterior chamber .pptx
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PPTX
Simulation of electric circuit laws using tinkercad.pptx
PPT
Drone Technology Electronics components_1
DOCX
573137875-Attendance-Management-System-original
PPTX
AgentX UiPath Community Webinar series - Delhi
Queuing formulas to evaluate throughputs and servers
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Chapter 6 Design in software Engineeing.ppt
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Lesson 3_Tessellation.pptx finite Mathematics
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
Internship_Presentation_Final engineering.pptx
anatomy of limbus and anterior chamber .pptx
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Simulation of electric circuit laws using tinkercad.pptx
Drone Technology Electronics components_1
573137875-Attendance-Management-System-original
AgentX UiPath Community Webinar series - Delhi

Recursion and Lambda Functions in python.ppt

  • 1. RECURSION AND LAMBDA FUNCTIONS VINAY AGRAWAL ASST. PROFESSOR CEA DEPT. GLA UNIVERSITY, MATHURA
  • 3. Tower of Hanoi Problem
  • 6. Programs 1. WAP to find the factorial of a number provided by user using Recursion. 2. WAP to print the fibonacci Series upto n terms, where n is provided by user. 3. WAP to find the GCD (or HCF) using Recursion. 4. WAP to input a string from the user and check whether it is palindrome or not.
  • 7. Lambda Functions or Anonymous Functions  Those Functions which does not have any name is called Anonymous Functions. In Python, this can be achieved by using keyword lambda, that’s why it is also called Lambda Functions.  They are not declared in the standard manner by using the def keyword  Lambda forms can take any number of arguments but return just one value in the form of an expression. They cannot contain commands or multiple expressions.
  • 8. Syntax  The syntax of lambda functions contains only a single statement, which is as follows: lambda arg1 ,arg2,.....argn:expression Example: add = lambda a, b : a + b print("Value of total : ", add( 10, 20 ) )
  • 9. Non-Anonymous Function Anonymous Function def square(x): return x*x n=int(input(“Enter the Number”)) print(square(n)) a=lambda x:x*x n=int(input(“Enter the Number”)) print(a(n))
  • 10. Lambda Function with map() function l=list(map(int,input().split())) Similarly L1=[1,2,3,4] L2=list(map(lambda x:x*x,L1)) print(L2) Output:[1,4,9,16]
  • 11. Lambda Function with filter() function L1=[1,2,3,4] L2=list(filter(lambda x:x%2==0,L1)) print(L2) Output:[2,4]
  • 12. Lambda Function with reduce() function import functools L1=[1,2,3,4,5,6,7,8,9,10] L2=functools.reduce((lambda a , b : a+b), L1) print(L2) Output:55