I have a list json_data:
> print(json_data)
> ['abc', 'bcd/chg', 'sdf', 'bvd', 'wer/ewe', 'sbc & osc']
I need to split those elements with '/', '&' or 'and' into two different elements. The result I am looking for should look like this:
>['abc', 'bcd', 'chg', 'sdf', 'bvd', 'wer', 'ewe', 'sbc' , 'osc']
The code is:
separators = ['/', 'and', '&']
titles = []
for i in json_data:
titles.extend([t.strip() for t in i.split(separators)
if i.strip() != ''])
When running it, I am getting an error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-d0db85078f05> in <module>()
5 titles = []
6 for i in json_data:
----> 7 titles.extend([t.strip() for t in i.split(separators)
8 if i.strip() != ''])
TypeError: Can't convert 'list' object to str implicitly
How can this be fixed?