I need help with something simple! I've tried different codes, but nothing worked properly.
I have a .txt file with two columns separated by space. The file looks like this:
I want to split these strings into a list to obtain the result below:
my_list=['1', 'abacaxi','1','abalo','1','abalos', '0', 'abacate']
How can I do this? The code below runs but the result is not what I need.
import os
import io
import sys
from pathlib import Path
while True:
try:
file_to_open =Path(input("Please, insert your file path: "))
with open(file_to_open,'r', encoding="utf-8") as f:
words = f.read().lower()
break
except FileNotFoundError:
print("\nFile not found. Better try again")
except IsADirectoryError:
print("\nIncorrect Directory path.Try again")
print('total number of words + articles: ', len(words))
corpus=words.split(' ')
print(corpus[0:20])