After listening to lecture 9, I'm still confused about the merge and sort functions, particularly the lambda function (here's the code: http://codepad.org/cutcMoyR). On line 39, what is "float.__lt__" and how does it interact with the lambda function? Also, when it's changed to "gt" for "greater than" instead, it sorts in reverse order. How does that work? Thanks!
Oops, the url got messed up. It's http://codepad.org/cutcMoyR . Sorry about that.
When you define a function, you can give the last argument[s] default values. This allows the function to be called with fewer arguments than the prototype calls for. In this case, if you called sort( L ), it would work using the lambda function for comparison. sort() is acutally being passed the __lt__ method from the Float class to do the comparisons, overriding the lambda, so they don't interact. It's an either or thing.
Oh okay, that makes sense. Thanks!
Join our real-time social learning platform and learn together with your friends!