Skip to content

Instantly share code, notes, and snippets.

@chulman444
Created December 14, 2017 20:13
Show Gist options
  • Save chulman444/7c3e5d16c33c257651ef20c489efd80f to your computer and use it in GitHub Desktop.
Save chulman444/7c3e5d16c33c257651ef20c489efd80f to your computer and use it in GitHub Desktop.
Typical code for typical work. I just forget things so why not use GIST
import json, sys
from functools import reduce
inputfilename = sys.argv[1]
outputfilename = sys.argv[2]
file = open(inputfilename, mode='r', encoding='utf-8')
raw = file.read()
file.close()
raw_json = json.loads(raw)
results = raw_json["response"]["results"]
words = [a["alternatives"][0]["words"] for a in results]
words_only = reduce(lambda a,b: a+b, words)
file = open(outputfilename, mode='w', encoding='utf-8')
file.write(json.dumps(words_only, ensure_ascii=False, indent=2))
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment