Question: I want to know what exactly is `lambda` in python? and where and why it is used.
thanks

Answer: 
Lambda is more of a concept or programming technique then anything else. 

Basically it's the idea that you get a function (a first-class object in python) returned as a result of another function instead of an object or primitive type. I know, it's confusing.

See this example from the [python documentation](http://docs.python.org/tutorial/controlflow.html#lambda-forms): 

```
def make_incrementor(n):
  return lambda x: x + n
f = make_incrementor(42)
f(0)
>>> 42
f(1)
>>> 43

```

So make\_incrementor creates a function that uses n in it's results. You could have a function that would increment a parameter by 2 like so: 

```
f2 = make_incrementor(2)
f2(3)
>>> 5

```

This is a very powerful idea in functional programming and functional programming languages like lisp & scheme. 

Hope this helps.
Lambda functions are not a Python specific concept, but are a general programming term for anonymous function, i.e. functions without a name. In Python they are commonly used where you need to pass a simple function as a parameter to another function.

The `sort` method on lists takes a parameter `key` which is a function that is used to calculate the value the list is sorted on. Imagine you are sorting a list of two element tuples, and you want to sort the list based on the first element. You need to pass a function to `key` which returns the first element. You could do this:

```
def first_element(x):
    return x[0]
my_list.sort(key=first_element)

```

or, much more concisely you can do:

```
my_list.sort(key=lambda x: x[0])

```