$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #121

Which fix removes the crash?

def parse(rows):
    return [int(r) for r in rows]

parse(['1', 'x', '3'])
  1. Keep only digits: filter with r.isdigit()
  2. Keep only digits: filter with r.isnumeric
  3. Wrap each int(r) in a bare try block
  4. Change the list into a generator instead
int() raises on a non-numeric string, which aborts the whole comprehension.
Play Problem Solving ▸