Skip to content

Instantly share code, notes, and snippets.

View PatrikHlobil's full-sized avatar

Patrik Hlobil PatrikHlobil

  • Karlsruhe, Germany
View GitHub Profile
@PatrikHlobil
PatrikHlobil / gist:9c633b597b2568d3f269c7d5c735974b
Created October 19, 2018 20:07
Delete Output of Jupyter Notebook file
import json
import os
#Define path of Jupyter notebook File:
notebook_path = r"c:\Users\Pat\Test.ipynb"
#Read in notebook as JSON and delete all output cells:
with open(notebook_path, "r") as f:
nb = json.load(f)
for i, cell in enumerate(nb["cells"]):
@PatrikHlobil
PatrikHlobil / nested_iterator.py
Last active February 9, 2024 23:29
Get all keys or values of a nested dictionary or list in Python
def iterate_all(iterable, returned="key"):
"""Returns an iterator that returns all keys or values
of a (nested) iterable.
Arguments:
- iterable: <list> or <dictionary>
- returned: <string> "key" or "value"
Returns: