Archive for the ‘Stupid Lambda Tricks’ Category

Get for Python Lists

With python’s dictionary objects, you have the useful get method: >>> d = {'a':1, 'b':2, 'c':3} >>> d.get('a') 1 >>> d.get('d', 'not found') 'not found' Sometimes, I find something like this would be useful for lists, using the list’s index in place of the dict’s key: >>> l = [0,1,2,3] >>> l.get(2) Traceback (most recent [...]

Weighty Choices

I was tasked at work last week with coming up with a 2 million+ record dataset for some load tests we’re running on our application. I had a day’s worth of production data that I need to extrapolate to six months. Another opportunity to use my favorite python module: random What I wanted was something [...]