Advertisement
here2share

# cast_list.py

Jul 20th, 2022
974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.20 KB | None | 0 0
  1. # cast_list.py
  2.  
  3. def cast_list(val):
  4.     return list(val) if isinstance(val, (tuple, list, set, dict)) else [val]
  5. cast_list('foo') # ['foo']
  6. cast_list([1]) # [1]
  7. cast_list(('foo', 'bar')) # ['foo', 'bar']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement