Reputation:
How can I obtain the expected result below?
data = ['abc', 'def', 'ghi']
Expected result is:
[abc, def, ghi]
My attempt is:
ans = [', '.join([''.join(i) for i in data])]
print ans
['abc, def, ghi']
Upvotes: 0
Views: 62
Reputation: 388
You could convert the list into a string, then use replace
to remove the quotation marks.
data = ['abc', 'def', 'ghi']
ans = str(data).replace('\'', '')
print(ans)
Output:
[abc, def, ghi]
Simples!
Upvotes: 1
Reputation: 329
Try below code:
>>> ans = '[' + ', '.join([''.join(i) for i in data]) + ']'
>>> ans
'[abc, def, ghi]'
>>>
Upvotes: 1