Refactoring some Python that used reduce and bit-fiddling. There's more than one way to do it in Python if you're determined enough.