Posts

Showing posts from September, 2011

Python programmer discovers functional programming. World keeps turning.

(e:feb 2015. I originally wrote this years ago when I was looking for a job and 'having a blog' was a question you were asked at interviews. This is nothing revolutionary, hell I'd rewrite the snippet now so it would yield the rows instead of constructing the entire table and returning it. But I felt good coming up with it back in the day.) Handling time series data using python’s builtin datastructures is a bitch. I guess the best way would be to just use a library like pandas , but a colleague came across the way I’d handled it in this code snippet using itertools and functools and asked me to share it with the rest of the team. I’ll just concentrate on the parts which require more explanation. The most complex line to understand is line 24 List comprehensions and python ‘switch’ row = dict([ (option, function_dict[option](series['list'])) for option in table_options ]) The dict function can build dictionaries in a variety of ways, a list pairs in m