user3476463
user3476463

Reputation: 4575

List to comma-separated string values

I have a list

['a','b','c']

I would like

'a','b','c'

I've tried

"','".join(tst)

but it returns a string

"a','b','c"

I need it in the format

'a','b','c'

for input to a function, can anyone suggest how to do this?

Upvotes: 0

Views: 53

Answers (3)

Riccardo Bucco
Riccardo Bucco

Reputation: 15364

This is very simple, you just need to unpack the list with the star * operator:

def f(a, b, c):
    print(a)
    print(b)
    print(c)

f(*['a', 'b', 'c'])

This will correctly prints

a
b
c

Upvotes: 0

chifu lin
chifu lin

Reputation: 156

Try it

str(['a','b','c']).strip('[]')

Upvotes: 0

Marc
Marc

Reputation: 3245

Add the single quote at the beginning and at the end:

"'"+"','".join(tst)+"'"

Upvotes: 2

Related Questions