Python - Return integer value for list enumeration
<p>Is there a cleaner way to get an integer value of the position of a list item in this code:</p>

<pre><code>a = ['m', 'rt', 'paaq', 'panc']
loc = [i for i, x in enumerate(a) if x == 'rt']
loc_str = str(loc).strip('[]')
loc_int = int(loc_str)
id_list = a[loc_int + 1:]
print id_list
</code></pre>

<p>Returns all items after 'rt' as a list ['paaq', 'panc']</p>

<p>Yes, use <code>list.index()</code>.</p>

<pre><code>a = ['m', 'rt', 'paaq', 'panc']
id_list = a[a.index('rt')+1:]
assert id_list == ['paaq', 'panc']
</code></pre>

<p>Or, to minimally change your program:</p>

<pre><code>a = ['m', 'rt', 'paaq', 'panc']
loc_int = a.index('rt')
id_list = a[loc_int + 1:]
print id_list
</code></pre>

<p>References:</p>

<ul>
<li><a href="https://docs.python.org/2/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange" rel="nofollow">https://docs.python.org/2/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange</a></li>
<li><a href="https://docs.python.org/2/tutorial/datastructures.html#more-on-lists" rel="nofollow">https://docs.python.org/2/tutorial/datastructures.html#more-on-lists</a></li>
</ul>

python enumerate