SlideShare a Scribd company logo
1 of 32
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
➢ Introduction to map() filter() reduce()
▪ The map() function
▪ The filter() function
▪ The reduce() function
➢ Using map() filter() and reduce() together
www.edureka.co/python
▪ filter() within map()
▪ map() within filter()
▪ filter() and map() within reduce()
Introduction to map(), filter() and
reduce()
www.edureka.co/python
Applies a given
function to all the
iterables and returns
a new list
Creates an output list
consisting of values for
which the function
returns true
Applies a given
function to the
iterables and returns a
single value
map() filter() reduce()
Introduction to map(), filter() and reduce()
www.edureka.co/python
www.edureka.co/python
1 2 3 4
map():
Applies a given function to all the iterables and returns a
new list.
output = map(lambda x: x+3 , [1,2,3,4])
www.edureka.co/python
1 2 3 4
map():
Applies a given function to all the iterables and returns a
new list.
output = map(lambda x: x+3 , [1,2,3,4])
www.edureka.co/python
1 2 3 4
4 5 6 7
map():
Applies a given function to all the iterables and returns a
new list.
output = map(lambda x: x+3 , [1,2,3,4])
www.edureka.co/python
www.edureka.co/python
filter()
Used to filter the given iterables(lists, sets, etc) with the help
of another function passed as an argument to test all the
elements to be true or false.
output = map(lambda x: (x>=3) , [1,2,3,4])
1 2 3 4
www.edureka.co/python
filter()
Used to filter the given iterables(lists, sets, etc) with the help
of another function passed as an argument to test all the
elements to be true or false.
output = map(lambda x: (x>=3) , [1,2,3,4])
1 2 3 4
www.edureka.co/python
filter()
Used to filter the given iterables(lists, sets, etc) with the help
of another function passed as an argument to test all the
elements to be true or false.
output = map(lambda x: (x>=3) , [1,2,3,4])
1 2 3 4
3 4
www.edureka.co/python
www.edureka.co/python
output = map(lambda x,y: x+y, [1,2,3,4])
reduce():
Applies some other function to a list of elements that are
passed as a parameter to it and finally returns a single
value.
1 2 3 4
output = map(lambda x,y: x+y, [1,2,3,4])
reduce():
Applies some other function to a list of elements that are
passed as a parameter to it and finally returns a single
value.
1 2 3 4
3
www.edureka.co/python
output = map(lambda x,y: x+y, [1,2,3,4])
reduce():
Applies some other function to a list of elements that are
passed as a parameter to it and finally returns a single
value.
1 2 3 4
3
6
www.edureka.co/python
output = map(lambda x,y: x+y, [1,2,3,4])
reduce():
Applies some other function to a list of elements that are
passed as a parameter to it and finally returns a single
value.
1 2 3 4
3
6
10
www.edureka.co/python
www.edureka.co/python
c = map(lambda x:x+x, )filter(lambda x: (x>=3), (1,2,3,4))
www.edureka.co/python
1 2 3 4
3 443
filter(lambda x: (x>=3), (1,2,3,4))
c = map(lambda x:x+x, )
www.edureka.co/python
,( ) )
1 2 3 4
3 4
43c = map(lambda x:x+x,
filter(lambda x: (x>=3), (1,2,3,4))
www.edureka.co/python
Filters out integers >=3 resulting in [3,4], then maps this using (x+x)
condition, you will get [6,8], which is the output.
www.edureka.co/python
c = filter(lambda x: (x>=3), )map(lambda x:x+x, (1,2,3,4))
www.edureka.co/python
c = filter(lambda x: (x>=3), )
map(lambda x:x+x, (1,2,3,4))
2 3 4
5 6 7
1
4
www.edureka.co/python
map(lambda x:x+x, (1,2,3,4))
1 2 3 4
c = filter(lambda x: (x>=3), )4 5 6 7( )), , ,
www.edureka.co/python
www.edureka.co/python
d = reduce ( lambda x, y: x+y, )map ( lambda x:x+x, filter ( lambda x: (x>=3) , (1,2,3,4)))
www.edureka.co/python
d = reduce ( lambda x, y: x+y, )
map ( lambda x:x+x, filter ( lambda x: (x>=3) , (1,2,3,4)))
1 2 3 4
3 443
86
www.edureka.co/python
d = reduce ( lambda x, y: x+y,
)
map ( lambda x:x+x, filter ( lambda x: (x>=3) , (1,2,3,4)))
1 2 3 4
3 443
86( , ))
www.edureka.co/python
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
www.edureka.co
www.edureka.co/python

More Related Content

What's hot

What's hot (20)

Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Python Lambda Function
Python Lambda FunctionPython Lambda Function
Python Lambda Function
 
Python list
Python listPython list
Python list
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
 
Python Generators
Python GeneratorsPython Generators
Python Generators
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
Advanced Python : Decorators
Advanced Python : DecoratorsAdvanced Python : Decorators
Advanced Python : Decorators
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG ManiaplPython Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG Maniapl
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Iterarators and generators in python
Iterarators and generators in pythonIterarators and generators in python
Iterarators and generators in python
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
 

Similar to How to use Map() Filter() and Reduce() functions in Python | Edureka

TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
Eelco Visser
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
riue
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
league
 

Similar to How to use Map() Filter() and Reduce() functions in Python | Edureka (20)

TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
Functions in advanced programming
Functions in advanced programmingFunctions in advanced programming
Functions in advanced programming
 
purrr.pdf
purrr.pdfpurrr.pdf
purrr.pdf
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function
 
Python High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptPython High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.ppt
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
 
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. Monads
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
Frp2016 3
Frp2016 3Frp2016 3
Frp2016 3
 
R Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdfR Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdf
 
Composition birds-and-recursion
Composition birds-and-recursionComposition birds-and-recursion
Composition birds-and-recursion
 
Practical cats
Practical catsPractical cats
Practical cats
 
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswiftSwift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
 
Differential calculus
Differential calculus  Differential calculus
Differential calculus
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 

More from Edureka!

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

How to use Map() Filter() and Reduce() functions in Python | Edureka

  • 1. Copyright © 2017, edureka and/or its affiliates. All rights reserved.
  • 2. ➢ Introduction to map() filter() reduce() ▪ The map() function ▪ The filter() function ▪ The reduce() function ➢ Using map() filter() and reduce() together www.edureka.co/python ▪ filter() within map() ▪ map() within filter() ▪ filter() and map() within reduce()
  • 3. Introduction to map(), filter() and reduce() www.edureka.co/python
  • 4. Applies a given function to all the iterables and returns a new list Creates an output list consisting of values for which the function returns true Applies a given function to the iterables and returns a single value map() filter() reduce() Introduction to map(), filter() and reduce() www.edureka.co/python
  • 6. 1 2 3 4 map(): Applies a given function to all the iterables and returns a new list. output = map(lambda x: x+3 , [1,2,3,4]) www.edureka.co/python
  • 7. 1 2 3 4 map(): Applies a given function to all the iterables and returns a new list. output = map(lambda x: x+3 , [1,2,3,4]) www.edureka.co/python
  • 8. 1 2 3 4 4 5 6 7 map(): Applies a given function to all the iterables and returns a new list. output = map(lambda x: x+3 , [1,2,3,4]) www.edureka.co/python
  • 10. filter() Used to filter the given iterables(lists, sets, etc) with the help of another function passed as an argument to test all the elements to be true or false. output = map(lambda x: (x>=3) , [1,2,3,4]) 1 2 3 4 www.edureka.co/python
  • 11. filter() Used to filter the given iterables(lists, sets, etc) with the help of another function passed as an argument to test all the elements to be true or false. output = map(lambda x: (x>=3) , [1,2,3,4]) 1 2 3 4 www.edureka.co/python
  • 12. filter() Used to filter the given iterables(lists, sets, etc) with the help of another function passed as an argument to test all the elements to be true or false. output = map(lambda x: (x>=3) , [1,2,3,4]) 1 2 3 4 3 4 www.edureka.co/python
  • 14. output = map(lambda x,y: x+y, [1,2,3,4]) reduce(): Applies some other function to a list of elements that are passed as a parameter to it and finally returns a single value. 1 2 3 4
  • 15. output = map(lambda x,y: x+y, [1,2,3,4]) reduce(): Applies some other function to a list of elements that are passed as a parameter to it and finally returns a single value. 1 2 3 4 3 www.edureka.co/python
  • 16. output = map(lambda x,y: x+y, [1,2,3,4]) reduce(): Applies some other function to a list of elements that are passed as a parameter to it and finally returns a single value. 1 2 3 4 3 6 www.edureka.co/python
  • 17. output = map(lambda x,y: x+y, [1,2,3,4]) reduce(): Applies some other function to a list of elements that are passed as a parameter to it and finally returns a single value. 1 2 3 4 3 6 10 www.edureka.co/python
  • 19.
  • 20. c = map(lambda x:x+x, )filter(lambda x: (x>=3), (1,2,3,4)) www.edureka.co/python
  • 21. 1 2 3 4 3 443 filter(lambda x: (x>=3), (1,2,3,4)) c = map(lambda x:x+x, ) www.edureka.co/python
  • 22. ,( ) ) 1 2 3 4 3 4 43c = map(lambda x:x+x, filter(lambda x: (x>=3), (1,2,3,4)) www.edureka.co/python Filters out integers >=3 resulting in [3,4], then maps this using (x+x) condition, you will get [6,8], which is the output.
  • 24. c = filter(lambda x: (x>=3), )map(lambda x:x+x, (1,2,3,4)) www.edureka.co/python
  • 25. c = filter(lambda x: (x>=3), ) map(lambda x:x+x, (1,2,3,4)) 2 3 4 5 6 7 1 4 www.edureka.co/python
  • 26. map(lambda x:x+x, (1,2,3,4)) 1 2 3 4 c = filter(lambda x: (x>=3), )4 5 6 7( )), , , www.edureka.co/python
  • 28. d = reduce ( lambda x, y: x+y, )map ( lambda x:x+x, filter ( lambda x: (x>=3) , (1,2,3,4))) www.edureka.co/python
  • 29. d = reduce ( lambda x, y: x+y, ) map ( lambda x:x+x, filter ( lambda x: (x>=3) , (1,2,3,4))) 1 2 3 4 3 443 86 www.edureka.co/python
  • 30. d = reduce ( lambda x, y: x+y, ) map ( lambda x:x+x, filter ( lambda x: (x>=3) , (1,2,3,4))) 1 2 3 4 3 443 86( , )) www.edureka.co/python
  • 31. Copyright © 2017, edureka and/or its affiliates. All rights reserved. www.edureka.co