Convert a Delimited String to a List in Python

Let’s say you have a string with values that are delimited by a comma. This would be common when parsing text files.

So suppose you have a delimited string:

x = "abc,def,ghi"

You can convert that into a Python list using the split function, passing the character that is delimiting the items:

y = x.split(",")
print y // ['abc', 'def', 'ghi']

Then you can access these individual items as you would with any list:

print y[0] // abc

Leave a Reply