Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

aschey

  • one year 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
    • one year 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
    • one year 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
    • one year 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

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.