Lambda can be any function. So if you had a function
def compare_person(a):
return a.age
You could sort a list of Person (each of which having an age attribute) like this:
sorted(personArray, key=compare_person)
This way, the list would be sorted by age in ascending order.
The parameter is called lambda because python has a nifty lambda keywords for defining such functions on the fly. Instead of defining a function compare_person and passing that to sorted, you can also write:
sorted(personArray, key=lambda a: a.age)
which does the same thing.