A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2003-September/222001.html below:

Finally found a use for lambda!

Finally found a use for lambda! Finally found a use for lambda!Roy Smith roy at panix.com
Sun Sep 14 22:28:39 EDT 2003
My apologies for a somewhat silly posting, but after 6 years of hacking 
Python, I finally found a use for lambda!  I wanted to write a unit test 
to prove that a given dictionary does not have a given key.  Since 
assertRaises requires its second argument to be something callable, 
instead of writing:

        self.assertRaises (KeyError, foo['bar'])

I had to write:

        self.assertRaises (KeyError, lambda: foo['bar'])

Of course, now that I think about it, I could have also written:

        self.assertEqual (foo.has_key ('bar')), 0)

so I guess I didn't really need the lambda after all :-)


More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4