366 B
366 B
title, tags
| title | tags |
|---|---|
| cast_list | utility,list,beginner |
Casts the provided value as an array if it's not one.
Use isinstance() to check if the given value is a list and return it as-is or encapsulated in a list accordingly.
def cast_list(val):
return val if isinstance(val, list) else [val]
cast_list('foo'); # ['foo']
cast_list([1]); # [1]