strsplit#

strsplit(string, sep=None, skipempty=True, lstrip=True, rstrip=True)[source]#

Convenience function to split common types of strings.

Note: to use regular expressions, use re.split() instead.

Parameters:
  • string (str) – the string to split

  • sep (str/list) – the types of separator to accept (default space or comma, i.e. [’ ‘, ‘,’])

  • skipempty (bool) – whether to skip empty entries (i.e. from consecutive delimiters)

  • lstrip (bool) – whether to strip any extra spaces on the left

  • rstrip (bool) – whether to strip any extra spaces on the right

Examples

sc.strsplit(‘a b c’) # Returns [‘a’, ‘b’, ‘c’] sc.strsplit(‘a,b,c’) # Returns [‘a’, ‘b’, ‘c’] sc.strsplit(‘a, b, c’) # Returns [‘a’, ‘b’, ‘c’] sc.strsplit(’ foo_bar ‘, sep=’_’) # Returns [‘foo’, ‘bar’]

New in version 2.0.0.