File size: 1,072 Bytes
99582b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# convert flashcards / table to multiple choice CSV
import csv
writer = csv.writer(open('./source2.csv', 'w'))
content = open('../genetic-counseling-multiple-choice-2.txt', 'r').read().split('ANSWER')
source = 'https://quizlet.com/527669083/abgc-practice-quiz-questions-flash-cards/'
author = 'laura7rohan'
writer.writerow(['source', 'author', 'question', 'optionA', 'optionB', 'optionC', 'optionD', 'letter_answer'])
for idx, q in enumerate(content):
if idx == len(content) - 1:
break
q_and_a = q[q.index('\n') + 1:].strip()
question = q_and_a[:q_and_a.index('A)')].strip()
option_A = q_and_a[q_and_a.index('\nA)') + 3 : q_and_a.index('\nB)')].strip()
option_B = q_and_a[q_and_a.index('\nB)') + 3 : q_and_a.index('\nC)')].strip()
option_C = q_and_a[q_and_a.index('\nC)') + 3 : q_and_a.index('\nD)')].strip()
option_D = q_and_a[q_and_a.index('\nD)') + 3 : ].strip()
letter_answer = content[idx + 1].split('\n')[0].strip()
writer.writerow([source, author, question, option_A, option_B, option_C, option_D, letter_answer])
|