You can read the text file line by line and split each line at the - character to get the questions. Here's a simple Python script to do this:
with open('path_to_your_file.txt', 'r') as file:
questions = []
for line in file:
if line.strip(): # Remove leading and trailing whitespace and check if the line is not empty
question = line.split('-')[0] # Split at the first '-' and get the first part (the question)
questions.append(question) # Add the question to the list
print(questions)
This script opens the specified file, reads each line, and appends the question part (everything before the -) to a list called questions. The strip() method is used to remove any leading and trailing whitespace from each line, and the if statement ensures that only non-empty lines are processed.
Please replace 'path_to_your_file.txt' with the actual path to your file on your computer.
If you have Python 3.6 or above, you can use the Path object from the pathlib module to handle file paths more easily:
from pathlib import Path
file_path = Path('path_to_your_file.txt')
questions = []
for line in file_path.open('r'):
# The rest of the code remains the same
This is a more robust way to handle file paths, as Path objects work seamlessly with the file system and support both relative and absolute paths.