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.
Merge pull request #950 from Renelvon/modern2

Use forward-compatible python (part 2)