Created
April 4, 2019 01:15
-
-
Save jiaxianhua/23c5fcef8cd114057a0dfb8190de273a to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import json | |
import collections | |
def readMd(mdfile): | |
with open(mdfile) as f: | |
lines = f.readlines() | |
lines = list(map(lambda l: l.rstrip(), lines)) | |
d = collections.OrderedDict({line: '' for line in lines}) | |
json_str = json.dumps(d) | |
return json_str | |
def readJson(json_str): | |
ordered_dict = json.loads(json_str, object_pairs_hook=collections.OrderedDict) | |
print(ordered_dict) | |
if __name__ == '__main__': | |
json_str = readMd('README.md') | |
readJson(json_str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment