10 examples of 'python convert string to list without split' in Python

Every line of 'python convert string to list without 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
this disclaimer
420def 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
Important

Use secure code every time

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

118def 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 != ""]
286def _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 []
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
33def 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
9def to_python(self, value):
10 return value.split(",")
13def listify(item):
14 if isinstance(item,basestring):
15 item = item.split('\n')
16 return item
100def strListToList(strlist):
101 """
102 Convert string in form of '"[33, 42, 43]", "[24, 43, 4]"'
103 into a normal list.
104 """
105
106 strlist = strlist.replace('"', '')
107 strlist = strlist.replace("'", "")
108 try:
109 listeval = ast.literal_eval(strlist)
110 return listeval
111 except ValueError:
112 raise ValueError("Failed to convert %s to list" % (strlist))
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()
45def extract_list(to_extract, separator, converter):
46 to_extract = to_extract.strip()
47 to_extract = ' '.join(to_extract.split())
48 string_list = [element.replace(" ", "") for element in to_extract.split(separator)]
49 return [converter(element) for element in string_list]

Related snippets