<p>我有一个名为values的字符串列表,我想让列表中的一个元素成为最后一个元素。例如,如果我有字符串:</p>
<pre><code>['string1', 'string2', 'string3']
</code></pre>
<p>我希望string2是最后一个元素:</p>
<pre><code>['string1', 'string3', 'string2']
</code></pre>
<p>当我的列表不包含string2时,也可能有一个实例。有什么简单的方法可以做到这一点吗?到目前为止,我所拥有的是:</p>
<pre><code>if 'string2' in values:
for i in values:
#remove string2 and <a href="https://www.cnpython.com/list/append" class="inner-link">append</a> to end
</code></pre>