If an item may not exist in a list, can we still do if-else to check condition?
<p>Suppose we have</p>

<pre><code>mystr = 'hello.py'
mystr = 'hello'
if not 'py' in mystr.rsplit('.')[1]:
</code></pre>

<p>The first case is fine, but the second case results in an "out of range" error. </p>

<p><strong>Goal:</strong> </p>

<p>If .py exists in the string, do nothing. If .py is not part of the filename, do XYZ.
Note : The user input may or may not have a .'extension-type'. </p>

<p><strong>Attempt:</strong></p>

<p>Either check the length, or convert the list into a string.</p>

<p>Any alternative? I am not sure if this is too localized. Just wondering. </p>

<p>Thanks.</p>
