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 :-)
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