擅长:python、mysql、java
<p>在这个示例代码中,可以使用字符串而不是list。它在列表的剩余部分中找到第一个x,然后在“x”之后找到第一个y,依此类推</p>
<pre><code>#mylist = [list to search]
i = 0
while true:
list_to_search = mylist[i:]
if 'x' not in list_to_search:
break
j = list_to_search.index('x')
if 'y' not in list_to_search[j+1:]:
break
i = list_to_search.index('y')
(x_pos,y_pos) = (j,i)
#your code
</code></pre>