Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

aschey

  • 3 years ago

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!

  • This Question is Closed
  1. aschey
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Oops, the url got messed up. It's http://codepad.org/cutcMoyR . Sorry about that.

  2. rsmith6559
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

  3. aschey
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Oh okay, that makes sense. Thanks!

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy