Create greedy.py (#1359)

* Create greedy.py

* Update greedy.py

* Add a doctest and format with black

* Update build_directory_md.py
This commit is contained in:
DanishSheikh1999
2019-10-22 14:25:01 +05:30
committed by Christian Clauss
parent 54830644a2
commit 13802fcca1
2 changed files with 65 additions and 4 deletions

View File

@ -25,7 +25,7 @@ def print_path(old_path: str, new_path: str) -> str:
for i, new_part in enumerate(new_path.split(os.sep)):
if i + 1 > len(old_parts) or old_parts[i] != new_part:
if new_part:
print(f"{md_prefix(i-1)} {new_part.replace('_', ' ').title()}")
print(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}")
return new_path
@ -36,9 +36,7 @@ def print_directory_md(top_dir: str = ".") -> None:
if filepath != old_path:
old_path = print_path(old_path, filepath)
indent = (filepath.count(os.sep) + 1) if filepath else 0
url = "/".join((URL_BASE, filepath.split(os.sep)[1], filename)).replace(
" ", "%20"
)
url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
filename = os.path.splitext(filename.replace("_", " "))[0]
print(f"{md_prefix(indent)} [{filename}]({url})")