# You can write small anonymous function with Lambda:
exclamation = lambda(a : a + '!')
exclamation('hello')
echo = (lambda word, e: world*e)
echo('hello',5)
# MAP() WITH LAMBDA FUNCTIONS
# map() applies a function over an object
l = ['a', 'b', 'c', 'd']
exclamation2 = map(lambda a : a+'!', l)
print(list(exclamation2))
# FILTER() WITH LAMBDA FUNCTIONS
# filter() is for filter out elements from a list that don't satisfy certain criteria
l = ['hello', 'hi', 'ciao', 'hola', 'marhabaan', 'hallo', 'alo']
longer = filter(lambda a : len(a) > 4, l)
print(list(longer))
# REDUCE() WITH LAMBDA FUNCTIONS
# reduce() is useful for performing some computation on a list and returns a single value
from functools import reduce
l = ['hello', 'hi', 'ciao', 'hola', 'marhabaan', 'hallo', 'alo']
result = reduce(lambda a, b : a + b, l)
print(result)
Categories
BOT
(2)
C#
(1)
Cluster Analysis
(1)
Data Cleaning
(6)
Data Ingestion
(1)
Data Science Specialization
(11)
Data Visualization
(13)
Hadoop
(1)
Machine Learning
(3)
MapReduce
(1)
Maps
(1)
Markdown
(5)
Market Basket Analysis
(1)
MATLAB
(1)
Matplotlib
(3)
Numpy
(1)
Octave
(1)
Pandas
(2)
Python
(13)
R
(20)
Regression
(4)
scikit-learn
(1)
Seaborn
(1)
Shiny App
(1)
SSIS
(3)
Statistical Inference
(2)
T-SQL
(9)

No comments:
Post a Comment