stocks ={
'BMW':40 ,
'FB': 90 ,
'whatsapp':100,
'Apple':30
}
print("lowest stock is : " , min(stocks ,key =lambda x:stocks[x]) )
this code works but i need to know how lambdas work in this context i know that it take an argument then return the result which is the expression ,so my question is what the argument which in this example lambda takes 'x' ,and does this argument change also or not .I mean does min function change it when it runs.so when min is called for first time what is the value of x.thanks in advance.
stocks[x]for that x. The main thing to note is thatminis accepting a function askeyon which to evaluate which value is smallest.key=stocks.getmax()function don't you understand? In your code, thexis will be one of the items in thestocksdictionary.