A few unsolicited code tips that seem to come up often if I may:
- `if <somestuff>: return True; else: return False` is always best spelled `return <somestuff>`
- You only need the global statement when you want to assign to a global, not access one
- `foo = d["bla"] if "bla" in d else None` is just `foo = d.get("bla")`
- You have mutable default args. They probably are not what you want. See http://docs.python-guide.org/en/latest/writing/gotchas/#muta... for e.g. for an explanation.
- Lots of your dicts with enumerates to set indices should just probably be lists
If I get a chance later I'll try to throw together a quick pull request, but otherwise, thanks for sharing.