Split on Any of Several Delimiters

Easy ⏱ 8 min 81% acceptance ★★★★★ 4.7
Survey answers separate items with commas, semicolons or pipes, plus stray spaces. Write tokens(text) using re.split on [,;|] with surrounding whitespace, dropping empty results.

Examples

Example 1
Input
tokens('python, sql; excel | power bi')
Output
['python', 'sql', 'excel', 'power bi']
Explanation

All three delimiters split; padding is trimmed.

Constraints

  • One re.split call.
  • No empty strings in the output.

Topics

Regular Expressionssplit

Companies

AccentureIBMWipro

Hints

Hint 1

r'\s*[,;|]\s*' eats the padding with the delimiter.

Hint 2

Filter falsy items after splitting.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.