Skip to content

Instantly share code, notes, and snippets.

@hxy9243
Last active August 11, 2019 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hxy9243/e034ac3bff151df8c2f3c2366dd1d8ba to your computer and use it in GitHub Desktop.
Save hxy9243/e034ac3bff151df8c2f3c2366dd1d8ba to your computer and use it in GitHub Desktop.
A snippet to generate Anki-compatible csv for flashcards
# 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