10 examples of 'how to return a list in python' in Python

Every line of 'how to return a list in python' 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
6def to_list(obj):
7 if isinstance(obj, list):
8 return obj
9 else:
10 return [obj]
40def _as_list(v: Any) -> List[Any]:
41 if v is None:
42 return []
43 if not isinstance(v, list):
44 return [v]
45 return v
156def as_list(value):
157 values = as_cr_separated_list(value)
158 result = []
159 for value in values:
160 if isinstance(value, string_types):
161 subvalues = value.split()
162 result.extend(subvalues)
163 else:
164 result.append(value)
165 return result
13def to_list(l):
14 return isinstance(l, list) and l or [l]
12def _get_list(value):
13 if isinstance(value, list):
14 return value
15 return [value]
84def to_list(value):
85 if value is None:
86 return None
87
88 return list(value)
9def to_python(self, value):
10 return value.split(",")
170def makeList(input):
171 if isinstance(input, basestring):
172 return [ input ]
173 elif input is None:
174 return [ ]
175 else:
176 return list(input)
15def _tolist(val):
16 if type(val) == list:
17 return val
18 lines = val.splitlines()
19 return [l.strip() for l in lines if l.strip()]
18def _to_list(path):
19 """
20 Guarantees that a list of strings will be returned.
21 Handles unicode caused by "%s" % path.path.
22 """
23 if isinstance(path,str) or isinstance(path,unicode):
24 path = [str(path)]
25 return path
26 else:
27 path = [str(x) for x in path]
28 return path

Related snippets