How would you make a comma-separated string from a list?
<p>What would be your preferred way to concatenate strings from a sequence such that between each two consecutive pair a comma is added. That is, how do you map, for instance, <code>[ 'a', 'b', 'c' ]</code> to <code>'a,b,c'</code>? (The cases <code>[ s ]</code> and <code>[]</code> should be mapped to <code>s</code> and <code>''</code>, respectively.)</p>

<p>I usually end up using something like <code>''.join(map(lambda x: x+',',l))[:-1]</code>, but also feeling somewhat unsatisfied.</p>

<p>Edit: I'm both ashamed and happy that the solution is so simple. Obviously I have hardly a clue as to what I'm doing. (I probably needed "simple" concatenation in the past and somehow memorised <code>s.join([e1,e2,...])</code> as a shorthand for <code>s+e1+e2+...</code>.)</p>

<pre><code>myList = ['a','b','c','d']
myString = ",".join(myList )
</code></pre>

<p>This won't work if the list contains numbers.</p>

<hr>

<p>As <a href="http://stackoverflow.com/users/3399/ricardo-reyes">Ricardo Reyes</a> suggested, if it contains non-string types (such as integers, floats, bools, None) then do:</p>

<pre><code>myList = ','.join(map(str, myList)) 
</code></pre>
