Pythonic idiom for checking the validity of a (negative) array index
<p>My function splits a string to lines, checks the index-th line, and returns one of two values. Here's a simplified version:</p>

<pre><code>def f(text, index):
   rows = text.split('\n')
   row = rows[index] # &lt;-- IndexError thrown here.
   if row_meets_some_condition:
      return "Yes"
   else:
      return "No"
</code></pre>

<p>The caller sometimes passes a negative value for <code>index</code> (when he wants to use end-of-file-based-indexing), which works fine, unless <code>text</code> haw too few lines, in which case I get an <code>IndexError</code> at the <code>row = rows[index]</code> line.</p>

<p>Is there an idiomatic way to check that <code>index</code> is a legal index into <code>rows</code>, other than catching the error?</p>
