Last active
August 11, 2019 21:27
-
-
Save hxy9243/e034ac3bff151df8c2f3c2366dd1d8ba to your computer and use it in GitHub Desktop.
A snippet to generate Anki-compatible csv for flashcards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gre.txt from plaintext in | |
# https://gre.economist.com/gre-advice/gre-vocabulary/which-words-study/most-common-gre-vocabulary-list-organized-difficulty | |
with open('gre.txt') as inf, \ | |
open('out.csv', 'w') as outf: | |
count = 0 | |
while True: | |
line = inf.readline() | |
if line == '': | |
break | |
sep = line.find(':') | |
word = line[:sep] | |
rest = line[sep + len(': '):].replace('\n', '</br></br>') | |
while line != '\n' and line != '': | |
line = inf.readline() | |
rest += line.replace('\n', '</br></br>') | |
outf.write((word + '\t' + rest + '\n\n')) | |
if count != 0 and count % 10 == 0: | |
print('Finished processing %d records' % count) | |
count += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment