Fix things pointed out by atagar's code review (Thanks!).

Mostly idiomatic python things. _format_circuit() was left as is for
readability reasons (and it's not in the critical path, so inefficiency
is a non-issue).