How to use 'python string split' in Python

Every line of 'python string split' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
1287def split(a, sep=None, maxsplit=None):
1288 """
1289 For each element in `a`, return a list of the words in the
1290 string, using `sep` as the delimiter string.
1291
1292 Calls `str.split` element-wise.
1293
1294 Parameters
1295 ----------
1296 a : array_like of str or unicode
1297
1298 sep : str or unicode, optional
1299 If `sep` is not specified or `None`, any whitespace string is a
1300 separator.
1301
1302 maxsplit : int, optional
1303 If `maxsplit` is given, at most `maxsplit` splits are done.
1304
1305 Returns
1306 -------
1307 out : ndarray
1308 Array of list objects
1309
1310 See also
1311 --------
1312 str.split, rsplit
1313
1314 """
1315 # This will return an array of lists of different sizes, so we
1316 # leave it as an object array
1317 return _vec_string(
1318 a, object_, 'split', [sep] + _clean_args(maxsplit))
285def rsplit(a_string, sep=None, maxsplit=None):
286 parts = a_string.split(sep)
287 if maxsplit is None or len(parts) <= maxsplit:
288 return parts
289 maxsplit_index = len(parts) - maxsplit
290 non_splitted_part = sep.join(parts[:maxsplit_index])
291 splitted = parts[maxsplit_index:]
292 return [non_splitted_part] + splitted

Related snippets