Refactor.

Check for key instead of catching KeyError.
Refactor.

Use enumerate instead of hand grown variable.
Use %d instead of %s for integral number.
Remove obsolete brackets.