Created
January 15, 2019 13:09
-
-
Save njanakiev/f8c819e25dec02f5339dfac71d4520b9 to your computer and use it in GitHub Desktop.
Jupyter Word Count
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 nbformat | |
filepath = 'notebbook.ipynb' | |
with open(filepath, 'r', encoding='utf-8') as f: | |
nb = nbformat.read(f, as_version=4) | |
wc_markdown, wc_heading, wc_code = 0, 0, 0 | |
for cell in nb.cells: | |
if cell.cell_type == "markdown": | |
wc_markdown += len(cell['source'].replace('#', '').lstrip().split(' ')) | |
elif cell.cell_type == "heading": | |
wc_heading += len(cell['source'].replace('#', '').lstrip().split(' ')) | |
elif cell.cell_type == "code": | |
wc_code += len(cell['source'].replace('#', '').lstrip().split(' ')) | |
print("Words in markdown : {}" .format(wc_markdown)) | |
print("Words in heading : {}" .format(wc_heading)) | |
print("Words in code : {}" .format(wc_code)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment