0

list:

['a','b']

Expected List:

['a,b']

Is there a pythonic way to do this?

ankit jain
  • 49
  • 2
  • 7
  • Can you give us a longer example? There are many ways to do it for the current example. Basically, we want to see whether the list is populated only by strings, or lists of lists with strings, etc. – Reti43 Apr 06 '16 at 19:44
  • 3
    So far this looks like a duplicate. https://stackoverflow.com/questions/12453580/concatenate-item-in-list-to-strings-python – Reti43 Apr 06 '16 at 19:47

2 Answers2

1
l2 = [','.join(l)]

There's not much point to wrapping this output in a list, though. It'd probably make more sense to just get the string:

joined_string = ','.join(l)
user2357112
  • 260,549
  • 28
  • 431
  • 505
0

You can use str.join

>>> l = ['a','b']
>>> [', '.join(l)]
['a, b']
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140