cute use of lambda

Terry Reedy tjreedy at udel.edu
Fri Sep 28 21:55:35 EDT 2007


"Simon Forman" <sajmikins at gmail.com> wrote in message 
news:1190945901.551940.165240 at k79g2000hse.googlegroups.com...
| class FakeQueue(list):
|    put = list.append
|    get = lambda self: self.pop(0)

Sorry, to me this is a foolish use of lambda as it is exactly the same as

  def get(self): self.pop(0)

except that in the latter, the resulting function object gets a proper 
internal name instead of '<lambda>', therefore giving a more informative 
traceback in case of an exception.

tjr






More information about the Python-list mailing list