fix cast_list
This commit is contained in:
@ -9,10 +9,13 @@ Use `isinstance()` to check if the given value is a list and return it as-is or
|
|||||||
|
|
||||||
```py
|
```py
|
||||||
def cast_list(val):
|
def cast_list(val):
|
||||||
return val if isinstance(val, list) else [val]
|
if isinstance(data, (tuple, list, set, dict)): return list(data)
|
||||||
|
elif data: return [data]
|
||||||
|
else: return []
|
||||||
```
|
```
|
||||||
|
|
||||||
```py
|
```py
|
||||||
cast_list('foo'); # ['foo']
|
cast_list('foo'); # ['foo']
|
||||||
cast_list([1]); # [1]
|
cast_list([1]); # [1]
|
||||||
|
cast_list(('foo', 'bar')); # ['foo', 'bar']
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user