How would you make a comma-separated string from a list of strings?
Why the map
/lambda
magic? Doesn't this work?
>>> foo = ['a', 'b', 'c']>>> print(','.join(foo))a,b,c>>> print(','.join([]))>>> print(','.join(['a']))a
In case if there are numbers in the list, you could use list comprehension:
>>> ','.join([str(x) for x in foo])
or a generator expression:
>>> ','.join(str(x) for x in foo)
",".join(l)
will not work for all cases. I'd suggest using the csv module with StringIO
import StringIOimport csvl = ['list','of','["""crazy"quotes"and\'',123,'other things']line = StringIO.StringIO()writer = csv.writer(line)writer.writerow(l)csvcontent = line.getvalue()# 'list,of,"[""""""crazy""quotes""and\'",123,other things\r\n'