Last active
June 21, 2021 20:01
-
-
Save Melbourneandrew/d6ed04bb5d7844048b5960a06b9c2922 to your computer and use it in GitHub Desktop.
Convert a text file(newline delimited) into an array saved in a json file
This file contains 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
import json | |
f = open('input.txt', 'r+') | |
lines = [line for line in f.readlines()] | |
f.close() | |
words = [] | |
for line in lines: | |
words.append(line.strip("\n")) | |
j = json.dumps(words) | |
with open("output.json", 'w') as outfile: | |
json.dump(words, outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment