import re def count_letters(string): try: assert bool(re.match('^\w+$', string)) return len(string) except AssertionError: return -1