Python for the .NET developer Transcripts
Chapter: The Python Language
Lecture: Concept: Lambda expressions

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Functions in Python are first-class objects.
0:02 You can pass them around, and one way you can define them
0:05 are through these lambda expressions.
0:08 So here we're sorting this in Nums, a list of numbers
0:11 and we want to specify how we're comparing
0:14 each individual element.
0:15 So we just create this lambda expression
0:18 given an input, or argument n, what do you want to do?
0:21 Here, we're actually going to sort
0:22 by the negative amplitude if it's an even number
0:26 and the positive amplitude if it's an odd number.
0:29 It sorts exactly as you would expect:
0:31 the first four, five numbers are even
0:34 so they're from largest to smallest
0:36 and then it switches to odd
0:38 so those are all sorted to the end
0:39 and then from there it goes up, up, up, up, up
0:42 even though there are some negative ones up near the top
0:45 their amplitude is, of course
0:47 like, amplitude 233 is bigger than 89.
0:50 How cool is that?