del builtin not functioning on list

32 Views Asked by At

So I'm trying to create a program that deletes the cells in jupyter notebook that are code cells and delete go into the cells that have the word solution and remove them. But when I use del it doesn't actually delete the dictionary from the list. I see that the data for ipynb is a dictionary of tuples that have lists that have dictionaries. dict>tup>lis>dict.

import json
import os
from pprint import pprint
import codecs

for filename in os.scandir("./multi_Test"):
    if filename.is_file():
        with codecs.open(filename.path, 'r') as r:
            # load data in json to manipulate
            data = json.load(r)
            # items in data all tuples
            tupl, v1, v2, v4 = data.items()
            # cells is a list of dictionaries
            cells = tupl[1]
            newcell = []
            for item in cells:
                if item['cell_type'] == 'code':
                    del item
                else:
                    for words in item['source']:
                        if 'Solution' in words:
                            del words

                    
            # dump data into new file
            smth = codecs.open("./something.ipynb", "w")
            json.dump(data, smth, indent="")
0

There are 0 best solutions below