Fix python3 issues in some examples

Unfortunately these are the easy ones ...

This mostly involves intervals/keys and xrange. For the most part I chose simplicity over minimising memory usage and replaced interkeys etc. with keys. The loops are rather short so the benefits from iterators is rather limited. If anyone thinks it is important I am happy to change this.
This does not actually reproduce the original python2 behaviour (ints are sorted before strings). Rather this converts the int to a string before sorting so 2 will be the same as '2' 

There don't seem to be an easy way to restore python2 sorting order without rolling out our own function which seems overkill in this case.