I have an array of strings like this:
Some Title##DD-MM-JJJJ##Some Text goes here##img1.jpg##img2.jpg I'd like to split this string at ##. My code is the following:
with open("raw_news.txt", "r") as f:
raw = []
for line in f:
line.strip()
line.split('##')
raw.append(line)
It doesn't work. I only get the single letters. re.split didn't do the trick, either. I'm really at a loss here, anyone knows what I'm doing wrong?
The problem is that you're disregarding the return value of split():
raw.append(line.split('##'))
For example:
In [5]: s = "Some Title##DD-MM-JJJJ##Some Text goes here##img1.jpg##img2.jpg"
In [6]: s.split("##")
Out[6]: ['Some Title', 'DD-MM-JJJJ', 'Some Text goes here', 'img1.jpg', 'img2.jpg']
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