Python For Og Lecture 65 - Lambda Expression Anonymous Function
Python For Og Lecture 65 - Lambda Expression Anonymous Function
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
pressure(10.1, 3500)
# lambda a, b: 0.052*a*b # --->>> SYNTAX --->>> lambda (arguments): what they will return
press(10.1, 3500)
# print the function name and varible name which contains the lambda expression
print(pressure)
print('----')
print(press)
# example 2
# we want to create functions where when one porosity value is given, that function will convert that fraction value into percent value
def fract(a):
return a*100
fract(0.24)
24.0
24.0
/
2/2/2021 Python for O&G Lecture 65: Lambda Expression (Anonymous Function) - Colaboratory
# define a function which calculates us the flow rate when all required data is given (Darcy law example, we have seen already)
# Given data:
def por(a):
if a<0.5:
print('Realistic porosity value')
else:
print('UNrealistic porosity value')
por(0.52)
/
por new lambda a: 'Realistic porosity value' if a<0 5 else 'Unrealistic porosity value'
2/2/2021 Python for O&G Lecture 65: Lambda Expression (Anonymous Function) - Colaboratory
por_new = lambda a: Realistic porosity value if a<0.5 else Unrealistic porosity value
por_new(0.7)
# PROBLEM:
# If i give a list to my lambda expression, ings were it returns me the list which contains reversed strings if length those strless than 5
def func_3(a):
rev = []
for i in a:
if len(i) < 5:
rev.append(i[::-1])
else:
rev.append(i)
return rev
func_3(list_1)
abc(list_1)