擅长:python、mysql、java
<p>使用enumerate获取数组中元素的索引。你知道吗</p>
<pre><code>l1 = ["eat","sleep","repeat"]
# printing the tuples in object directly
for ele in enumerate(l1):
print ele
Output:
(0, 'eat')
(1, 'sleep')
(2, 'repeat')
</code></pre>
<p>上述代码也可以使用同样的方法。你知道吗</p>
<pre><code>listo = [[1,2,3],[4,5]]
for ind,x in enumerate(listo):
if 3 in x:
print(ind)
</code></pre>