Tag: Lambda
C++11 Lambda Function : Example & Tutorial
In this article we will discuss, what is a C++11 Lambda Functions, how to use Lambda Functions as Callbacks. What is a Lambda Function? Lambda functions are a kind of anonymous functions in C++. These are mainly used as callbacks in C++. Lambda function is like a normal function i.e. Advertisements You can pass arguments to …
C++ : How to Sort a List of objects with custom Comparator or lambda function
In this example we will discuss different ways to sort a std::list of user defined data types with custom comparators or lambda functions. Suppose we have a type Player that contains Id and name. Advertisements struct Player { int id; std::string name; Player(int playerId, std::string playerName) : id(playerId), name(playerName) { } bool operator <(const Player …
C++ : How to Sort a List of objects with custom Comparator or lambda functionRead More
C++11 Lambda : How to capture local variables inside Lambda ?
In this article we will discuss how to capture local variables from outer scope in Lambda. A simple Lambda syntax is, Advertisements [Captured variables](paameters) { function code } Local variables from outer scope can be captured inside Lambda in 2 modes i.e. By Value By Reference Capturing Local Variables by value inside Lambda Function To …
C++11 Lambda : How to capture local variables inside Lambda ?Read More
C++11 Lambda : How to capture member variables inside Lambda function
In this article we will discuss how to capture member variables from outer scope. Suppose we have a class OddCounter to keep the track of odd numbers read by the object. Inside its member function we are creating a lambda function and passing to a STL algorithm std::for_each. Advertisements Now this lambda function needs to capture …
C++11 Lambda : How to capture member variables inside Lambda functionRead More
Python: How to sort a list of tuples by 2nd Item using Lambda Function or Comparator
In this article we will discuss how to sort a list of tuple using 2nd or i th item of tuple. Suppose we have a list of tuple i.e. words and thier frequency count, Advertisements # List of tuples i.e. word and its frequency count wordFreq = [ (‘the’ , 34) , (‘at’ , 23), …
Python: How to sort a list of tuples by 2nd Item using Lambda Function or ComparatorRead More
Why do we need Lambda functions in Python ? | Explained with examples.
In this article we will discuss what is a lambda function in python and why they are required. Basically what are the use cases which makes use of lambda function must. What is a lambda function ? Lambda functions are also called Anonymous functions because they don’t have any name. Also they can be assigned …
Why do we need Lambda functions in Python ? | Explained with examples.Read More
Python : How to use if, else & elif in Lambda Functions
In this article we will discuss how to use if , else if and else in a lambda functions in Python. Will also explain how to use conditional lambda function with filter() in python. Using if else in Lambda function Using if else in lambda function is little tricky, the syntax is as follows, lambda …
Python : How to use if, else & elif in Lambda FunctionsRead More