Every line of 'python split string into list of 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]
126 def 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
7 def split_string(s, n): 8 return [s[i*n:i*n+n] for i, j in enumerate(s[::n])]
54 def 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
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
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
59 @register.function 60 def char_split(value, names=None, char="$"): 61 value_list = value.split(char) 62 63 if names is not None: 64 return dict(zip(names, value_list)) 65 66 return value_list
143 def _split_basic(string): 144 """ 145 Split a string into a list of tuples of the form (key, modifier_fn, 146 explode) where modifier_fn is a function that applies the appropriate 147 modification to the variable. 148 """ 149 tuples = [] 150 for word in string.split(','): 151 # Attempt to split on colon 152 parts = word.split(':', 2) 153 key, modifier_fn, explode = parts[0], _identity, False 154 if len(parts) > 1: 155 modifier_fn = functools.partial( 156 _truncate, num_chars=int(parts[1])) 157 if word[len(word) - 1] == '*': 158 key = word[:len(word) - 1] 159 explode = True 160 tuples.append((key, modifier_fn, explode)) 161 return tuples
1287 def 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))
420 def convert_list_str(string_list, type): 421 """ 422 Receive a string and then converts it into a list of selected type 423 """ 424 new_type_list = (string_list).split(",") 425 for inew_type_list, ele in enumerate(new_type_list): 426 if type is "int": 427 new_type_list[inew_type_list] = int(ele) 428 elif type is "float": 429 new_type_list[inew_type_list] = float(ele) 430 431 return new_type_list