Skip to main content

Posts

Showing posts from June, 2018

Lambda functions in Python

Lambda functions are simply functions that don't have a name. They are also called anonymous functions and are pretty useful for certain cases. They are extensively used in functional programming . Lambda expression is useful for creating small, one time use functions though the functions can also be given a name. It can have multiple arguments but just a single expression as the function body. The basic syntax to create a lambda function is lambda arguments: function body For example lambda x : x **2 This function takes in x and returns x 2 . Here, lambda is the keyword, x is the argument and the expression after the colon is the function body. These functions can also be given a name, sqr = lambda x : x **2 sqr(5) #output : 25 Multiple arguments can also be provided lambda x,y: x * y or lambda x,y,z: x*y*z These functions when given a name are equivalent to the functions defined by using the def keyword. For example def solve_quad(a,b,c): d = b**2 - (4*a*c) x1

Kattis | The coding platform

Recently I came across a new website for competitive coding, Kattis and I love it. It is such an amazing platform and has a plethora of question along with multiple long duration contests. The quality of questions is also good and the interface is also very intutive. Follow this link to go to Kattis .