News for hackers. Stuff that matters.
Re:A Python Guide for the Ages by montebicyclelo on Sunday December 26, 2021 @02:30AM (#29690467)
Aha, thank you. Yes, it's plausible that my brain did pair the `else` with the `if`, even though it knew it was supposed to be paired with the `for`.

Before being introduced to `for`/`else`, I'd have written the example you gave as:

  result = None
  for i in range(n):
      if search(i) == val:
          result = i
  if not result:
      raise KeyError("not found")

There are no comments on this comment yet.