Use isinstance instead of comparing types.

* This is more idiomatic Python and prevents failure in case of
  subclassed types.
Use set literals.
Drop redundant len in boolean contexts.