Fixed case mismatch problem and made other code improvements

made loop breaking more Pythonic; made character checking O(1) instead of O(n)

Thanks for the great tutorial!