擅长:python、mysql、java
<p>鉴于您已经正确地解决了问题,这里有一个解决方案:</p>
<pre><code>def not_buggy_join(input, sep=","):
return sep.join(map(str, input))
</code></pre>
<p>从<a href="http://docs.python.org/2/library/functions.html#map" rel="nofollow">the documentation</a>,<code>map(function, iterable)</code>将</p>
<blockquote>
<p>Apply <code>function</code> to every item of <code>iterable</code> and return a list of the results.</p>
</blockquote>
<p>在本例中,它将所有内容转换为<code>str</code>。用你自己的例子:</p>
<pre><code>>>> not_buggy_join(itertools.chain(*enumerate("abc")))
'0,a,1,b,2,c'
</code></pre>