Fix Python – Split a string by a delimiter in python

Question

Asked By – Hulk

How to split this string where __ is the delimiter

MATCHES__STRING

To get an output of ['MATCHES', 'STRING']?

Now we will see solution for issue: Split a string by a delimiter in python


Answer

You can use the str.split method: string.split('__')

>>> "MATCHES__STRING".split("__")
['MATCHES', 'STRING']

This question is answered By – adamk

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0