This isn't a nit or anything, just some thoughts. This looks a lot like what you'd use a switch/case statement in other languages. In Python you can do it with a bunch of ifs, but sometimes it's nicer to put all the bodies in functions and use a dict. The advantage to using a dict is that it's faster lookup on average for cases where "faster" in this case isn't enough of a boost to make a huge difference. If this was in a tight-loop somewhere, then it'd be worth switching to a dict.