Make code slightly more Pythonic

This doesn't make EVERYTHING more pythonic, but it's a huge step forward - mostly taking advantage of Python builtins and syntax, with some formatting.