Every line of 'python split string by comma into list' 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.
118 def convert_list_comma(s): 119 """ 120 Return a list object from the <s>. 121 Consider <s> is comma delimited. 122 """ 123 if s is None: 124 return [] 125 if isinstance(s, list): 126 return s 127 return [word for word in re.split(r"\s*,\s*", s.strip()) if word != ""]
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
286 def _split_list(value): 287 """Split a string list into parts.""" 288 if value: 289 return [p for p in LIST_SEP_RE.split(value) if p] 290 else: 291 return []
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
74 def split_comma_semicolon_lists(s, dtype=None): 75 """TODO 76 Parameters 77 ---------- 78 s 79 Input string 80 dtype: optional 81 Data type to impose upon values 82 """ 83 res = [] 84 for x in s.split(";"): 85 if not ':' in x: 86 raise ValueError("Each entry must be in the form key:values," 87 " e.g. 'targets:rest'") 88 key, s_values = x.split(':', 1) 89 values = s_values.split(',') 90 if dtype is not None: 91 values = [dtype(v) for v in values] 92 res.append((key, values)) 93 return res
33 def to_list(a, delimiter=',', mapping=None): 34 l = a.split(delimiter) 35 if mapping: 36 l = [mapping[li] for li in l] 37 38 return l
9 def comma_list(list_str, item_func=None): 10 if not list_str: 11 raise ArgumentTypeError("Invalid comma list") 12 item_func = item_func or (lambda i: i) 13 return [item_func(i.strip()) for i in list_str.split(",") if i.strip()]
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
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]
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
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