-
Notifications
You must be signed in to change notification settings - Fork 3
Lambda, map() and filter()
surendrabisht edited this page Jul 14, 2020
·
2 revisions
A lambda function is a small anonymous function.
Syntax: <lambda arguments> : <expression>
Ex:
reverse = lambda string : string[::-1]
print(reverse("Lambda"))
The map() function executes a specified function for each item in a iterable. The item is sent to the function as a parameter.
syntax: map(function,collection)
nos = [9,11,15]
doubleOfnos = map(lambda no: no*2, nos)
for x in doubleOfnos:
print(x)
The filter() method constructs an iterator from elements of an iterable for which a function returns true.
syntax: filter(function,collection)
ages = [5, 12, 17, 18, 24, 32]
adults = filter(lambda age: age>18, ages)
for x in adults:
print(x)
Keep Learning. Never Settle! 😊
- Home
- 1.Introduction To Python
- 2. DataTypes
- 3. Strings and Slicing of collection
- 4.If else & Loops
- 5. Break, continue, pass
- 6. Functions
- 7. Modules
- 8. Clarifying basics
- 9. File Handling
- 10. Exception Handling
- 11. Dig into Collections
- 12. Iterators, Generators and list comprehension
- 13. lambdas , map, filter and other concepts
- 14. args, kwargs an default parameters
- 15. Functional Programming
- 16. OOPs