Search code examples
pythonstringsplitseparator

How to split python strings with multiple separators?


I've string which includes some irrelevant characters for example :

"t1, t2, t3"

If I'm splitting it by split(",") method I'm getting a list where second and third items include also the white space.

How can I split required string with multiply separator ?


Solution

  • If you don't need whitespace you could use :

    "t1, t2, t3,t4".replace(" ", "").split(",")