How would you make a comma-separated string from a list in Python?

PythonServer Side ProgrammingProgramming

Python has an in-built join() function that returns a string by joining elements in a sequence object by inserting separator between elements. If we need a string without any separator, we initialize it with null string. For a comma separated string, initialize the variable to ‘,’.

>>> lst=['h','e','l','l','o']
>>> str=','
>>> str.join(lst)
'h,e,l,l,o'
raja
Published on 02-Jan-2018 00:04:13
Advertisements