10 examples of 'python split string by space' in Python

Every line of 'python split string by space' 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
113def split(string, char):
114 """ Split a string with a char and return always two parts"""
115 string_list = string.split(char)
116 if len(string_list) == 1:
117 return None, None
118 return char.join(string_list[:-1]), string_list[-1]
126def split_string(input_string):
127 '''Split a string to a list and strip it
128 :param input_string: A string that contains semicolons as separators.
129 '''
130 string_splitted = input_string.split(';')
131 # Remove whitespace at the beginning and end of each string
132 strings_striped = [string.strip() for string in string_splitted]
133 return strings_striped
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
23def split(self, exp: str) -> list:
24 return self.content.split(exp)
21def splitter(line):
22 return line.split()
7def split_string(s, n):
8 return [s[i*n:i*n+n] for i, j in enumerate(s[::n])]
54def split_whitespace_separated_str(src, preserve_whitespaces=False):
55 rgxp = re.compile(" *[^ ]+ *") if preserve_whitespaces else re.compile("[^ ]+")
56 result = []
57 for m in rgxp.finditer(src):
58 result.append(m.group())
59 if preserve_whitespaces and len(result) > 1:
60 for i in range(len(result) - 1):
61 result[i] = result[i][:-1]
62 return result
263def multi_split(s, seps):
264 res = [s]
265 for sep in seps:
266 s, res = res, []
267 for seq in s:
268 res += seq.split(sep)
269 return res
86def tokenise_string(string):
87 """
88 Splits the passed string into a list of strings, delimited by a space character
89 """
90 return string.split()

Related snippets