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

Every line of 'python convert string to 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
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
1337def ConvertToPythonStringList(to_convert):
1338 '''
1339 Converts a python string list to a format more suitable for GUI representation
1340 @param to_convert:: The string list
1341 '''
1342 return su.convert_to_string_list(to_convert)
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))
84def to_list(value):
85 if value is None:
86 return None
87
88 return list(value)
13def to_list(l):
14 return isinstance(l, list) and l or [l]
66def to_list(x, default=None):
67 if x is None:
68 return default
69 if not isinstance(x, (list, tuple)):
70 return [x]
71 else:
72 return x
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 != ""]</s></s>
9def to_python(self, value):
10 return value.split(",")
51def get_value_as_str_list(value):
52 if value is None:
53 return []
54 elif isinstance(value, str):
55 return [value]
56 else:
57 return value
6def to_list(obj):
7 if isinstance(obj, list):
8 return obj
9 else:
10 return [obj]

Related snippets