I have a string like this:
'|Action and Adventure|Drama|Science-Fiction|Fantasy|'
How can I convert it to a tuple or a list?
Thanks.
>>> s = '|Action and Adventure|Drama|Science-Fiction|Fantasy|'
>>>
>>> [item for item in s.split('|') if item.strip()]
['Action and Adventure', 'Drama', 'Science-Fiction', 'Fantasy']
>>>
If you'd rather have a tuple then:
>>> tuple(item for item in s.split('|') if item.strip())
('Action and Adventure', 'Drama', 'Science-Fiction', 'Fantasy')
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With