a particularly anal PEP8 go through, and some little tweaks

@andrewphilipsmith I've gone through this in vim with pylint and pyflakes on, and kept resolving things until the little quickfix window vanishes (that's my litmus test). Also simplified a couple of bits (removed reduce in favour of using string.join), and added some notes (there's a possible vulnerability in the aggregator, though I guess it probably doesn't "matter" since it's in-memory, but may cause errors anyway).

Haven't tested this yet, so this was a pure code-reading exercise!

(Sorry - recreated as I didn't want to PR into master)
see https://docs.python.org/2/library/sqlite3.html, but I'm not sure how well that plays with aggregator functions (I've never used them).