擅长:python、mysql、java
<p>你让事情变得更难了。您只需将<code>join()</code>直接用于列表:</p>
<pre><code>my_list = ['3.3.3.3', '2.2.2.3', '2.2.2.2']
s = '"(' + '|'.join(my_list) + ')"'
# s is "(3.3.3.3|2.2.2.3|2.2.2.2)"
# with quotes as part of the string
</code></pre>
<p>或者如果你喜欢<code>format</code>:</p>
<pre><code>s = '"({})"'.format('|'.join(my_list))
</code></pre>