I have a txt file that I need to convert into a table. If I have a case like this:
---------------------------------------------
|apple|very good|every day|fruit
|chocolate|not so good|just\n
some times|snack
|bread|good|every day|whole|carbs
---------------------------------------
I splitted the file on the '|' but the new line is a problem I cannot overcome, how can I join the two lines?
with open("ridotto.txt", encoding='latin-1') as f:
new_list=[]
for line in f:
if line.startswith("-"):
line.replace("-", "")
else:
new_list.append(line.replace('\n', ' ').split('|'))
When I do this I get as a result:
[apple,very good,every day,fruit,chocolate, not so good, just ,some times, snack,bread, good, every day, whole, carbs]
while I want just some times to be one singular element Note: the \n is not literal