1
0
Fork 0
mirror of https://github.com/satwikkansal/wtfpython synced 2025-07-04 20:38:06 +02:00

Shots fired!y

This commit is contained in:
Satwik Kansal 2018-01-17 23:01:51 +05:30
parent 33b38f1835
commit ba6870a46e
2 changed files with 95 additions and 2 deletions

36
parse_readme.py Normal file
View file

@ -0,0 +1,36 @@
import pprint
fname = "README.md"
snipepts = []
with open(fname, 'r') as f:
lines = f.readlines()
iterator
while iterator:
# check if it's a H3
if line.startswith("###"):
title = line.replace("### ", "")
description = ''
next_line = itertor.next
while not next_line.startswith("#### "):
# store lines till an H4 (explanation) is encountered
description.append(next_line)
next_line = iterator.next
# store lines again until --- or another H3 is encountered
snippets.append({
"title":,
"description":,
"explanation":
})
# repeat until EOL is encoutered
# separating by category
categories = ["a", "b", "c"]
snips_by_cat = {k:[] for k in categories}
for snip in snippets:
cat = raw_input(snip["title"])
snips_by_cat[cat].append(snip)
pprint.pprint(snips_by_cat)