I have a text file with questions separated by a single "-" character. Something like…
- User
I have a text file with questions separated by a single "-" character. Something like this:
Why is the sky blue?
What is your favorite color: a) blue b) red c) green d) none of the above
Do you like pizza?
etc.
I'd like to read this file into a list in Python, so that each question is an element in this list. How do I do that?
Assistant
Here is how you can read that file into a list with each question as a separate element:
with open('questions.txt') as f: content = f.read() questions = content.split('-\n') questions = [q.strip() for q in questions if q.strip()]Let's break this down:
- Open the file for reading
- Read the entire contents into a string
content - Split the string on the delimiter (dash followed by newline)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.