Split a string by a delimiter in python

Hulk picture Hulk · Aug 13, 2010 · Viewed 427.8k times · Source

How to split this string where __ is the delimiter

MATCHES__STRING

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

Answer

adamk picture adamk · Aug 13, 2010

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

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