title: Conditional statement in a one line lambda function in python?
body: <p>Apologies if this has been asked before, but I couldn't see it anywhere.</p>
  
  <p>Essentially I've come across a scenario where i need to make use of an if statement inside a lambda function. What makes it difficult is that ideally it needs to be in a single line of code (if thats even possible?)</p>
  
  <p>Normally, i would write this:</p>
  
  <pre><code>T = 250
  
  if (T &gt; 200):
      rate = 200*exp(-T)
  else:
      rate = 400*exp(-T)
  
  return (rate)
  </code></pre>
  
  <p>However i need it to look like this:</p>
  
  <pre><code>rate = lambda(T) : if (T&gt;200): return(200*exp(-T)); else: return(400*exp(-T))
  </code></pre>
  
  <p>I realize the easier thing to do would to take the decision making outside of the lambda functions, and then have a separate lambda function for each case, but its not really suitable here. The lambda functions are stored in an array and accessed when needed, with each array element corresponding to a particular "rate" so having two separate rows for the same "rate" would mess things up. Any help would be greatly appreciated, or if its not possible, some confirmation from others would be nice :)</p>