<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    On 3/19/2011 9:44 AM, Ajit Deshpande wrote:
    <blockquote
      cite="mid:AANLkTinpK0AwjEGH2kKdSHuLMx_kfDzjsbjXkDVkJNpK@mail.gmail.com"
      type="cite">I am trying to figure out where lambda functions can
      be useful. Has anyone used them in real world?<br>
      <br>
      From my reading so far, I hear people claim that lambda can be a
      useful replacement for small functions. Most examples  didn't make
      much sense to me. Why would anyone use a one liner anonymous
      function, if you never plan to use it elsewhere? You would then be
      implementing the logic directly in the line, isn't it?. Functions
      are useful if they plan to get called multiple times within your
      code.<br>
      <br>
      For example:<br>
      <br>
      add_one = lambda x: x + 1<br>
      <br>
      In real world, why would I use a lambda for this. I would simply
      do:<br>
      <br>
      add_one = x + 1<br>
      <br>
      Can you provide some useful use cases for lambda functions?<br>
    </blockquote>
    <br>
    One is the list sort method.<br>
    <br>
    someList.<span class="pre">sort([cmp[,</span> <span class="pre">key[,</span>
    <span class="pre">reverse]]])<br>
      <br>
    </span><em>"cmp</em> specifies a custom comparison function of two
    arguments (list items) which should return a negative, zero or
    positive number depending on whether the first argument is
    considered smaller than, equal to, or larger than the second
    argument: <tt class="docutils literal"><span class="pre">cmp=lambda</span>
      <span class="pre">x,y:</span> <span class="pre">cmp(x.lower(),</span>
      <span class="pre">y.lower())</span></tt>."<br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Bob Gailer
919-636-4239
Chapel Hill NC</pre>
  </body>
</html>