How clever is the python interpreter?
<p>Probably a stupid question, but I am wondering in general, and if anyone knows, how much foresight the Python interpreter has, specifically in the field of regular expressions and text parsing.</p>

<p>Suppose my code at some point looks like this:</p>

<pre><code>mylist = ['a', 'b', 'c', ... ]

if 'g' in list: print(mylist.index('g'))
</code></pre>

<p>is there any safer way to do this with a while loop or similar. I mean, will the index be looked up with a second parsing from the beginning or are the two g's (in the above line) the same thing in Python's mind?</p>
