Every line of 'python split by multiple characters' 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.
113 def 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]
166 def split(self, row): 167 splitter = (row.startswith('| ') and self._split_from_pipes 168 or self._split_from_spaces) 169 for value in splitter(row): 170 yield value 171 yield '\n'
263 def 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
21 def splitter(line): 22 return line.split()
176 @pytest.mark.parametrize('s, maxsplit', 177 [("foo bar baz", 1), (" foo bar baz ", 0)], 178 ids=repr) 179 def test_str_split_maxsplit(self, s, maxsplit): 180 """Test if the behavior matches str.split with given maxsplit.""" 181 actual = split.simple_split(s, maxsplit=maxsplit) 182 expected = s.rstrip().split(maxsplit=maxsplit) 183 assert actual == expected
29 def escapedsplitby(inputstring, separator): 30 """Splits inputstring with separator and using "\" as a escape character""" 31 # TODO check alternatives (shlex and csv) 32 result = [] 33 while inputstring[0] == separator: 34 inputstring = inputstring[1:] 35 lastindex = 0 36 index = 0 37 while index < len(inputstring): 38 if inputstring[index] == "\\" and inputstring[index + 1] == separator: 39 inputstring = inputstring[:index] + inputstring[index + 1:] 40 index += 1 41 continue 42 elif inputstring[index] == "\\" and inputstring[index + 1] == "\\": 43 inputstring = inputstring[:index] + inputstring[index + 1:] 44 index += 1 45 continue 46 elif inputstring[index] == separator: 47 result.append(inputstring[lastindex:index]) 48 while inputstring[index] == separator: 49 index += 1 50 lastindex = index 51 continue 52 else: 53 index += 1 54 continue 55 result.append(inputstring[lastindex:]) 56 return result
27 def escapedsplitby(inputstring, separator): 28 """Splits inputstring with separator and using "\" as a escape character""" 29 #TODO check alternatives (shlex and csv) 30 result = [] 31 while inputstring[0] == separator: 32 inputstring = inputstring[1:] 33 lastindex = 0 34 index = 0 35 while index < len(inputstring): 36 if inputstring[index] == "\\" and inputstring[index + 1] == separator: 37 inputstring = inputstring[:index] + inputstring[index + 1:] 38 index += 1 39 continue 40 elif inputstring[index] == "\\" and inputstring[index + 1] == "\\": 41 inputstring = inputstring[:index] + inputstring[index + 1:] 42 index += 1 43 continue 44 elif inputstring[index] == separator: 45 result.append(inputstring[lastindex:index]) 46 while inputstring[index] == separator: 47 index += 1 48 lastindex = index 49 continue 50 else: 51 index += 1 52 continue 53 result.append(inputstring[lastindex:]) 54 return result
98 def _split_escape(str): 99 """Splits string by dots, unless dot is escaped. 100 101 foo.bar results in ["foo", "bar"] 102 103 foo\\.bar results in ["foo.bar"] 104 """ 105 return [_remove_escapes(x) for x in re.split(r"(?\\)\.", str)]
37 def _itersplit(l, splitters): 38 current = [] 39 for item in l: 40 if item in splitters: 41 yield current 42 current = [] 43 else: 44 current.append(item) 45 yield current
285 def 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