def delete_top_level(self, context=None):
        """
        Delete the top level calls which are not part of the user's code.

        TODO: If CELL_MAGIC then also merge the entries for the cell (which are
        seperated by line into individual code objects...)
        """
        if context == "LINE_MAGIC":
            # Find the root nodes that we want
            new_roots = []
            for function in self.cprofile_tree:
                try:
                    if function.co_name == "<module>":
                        new_roots += self.cprofile_tree[function]['calls']
                except AttributeError:
                    pass

            # Remove function from new_roots if its child is already in
            # new_roots
            new_roots = [r for r in new_roots if (type(r) == str or
                                                  r.co_name != "<module>")]
            for i in range(len(new_roots)):
                function = new_roots[i]
                try:
                    if function.co_name == "<module>":
                        del new_roots[i]
                except AttributeError:
                    pass

        if context == "CELL_MAGIC":
            # Find the root nodes that we want
            new_roots = []
            for function in self.cprofile_tree:
                try:
                    if "<ipython-input" in function.co_filename:
                        new_roots += self.cprofile_tree[function]['calls']
                except AttributeError:
                    pass

        # Populate a new tree with everything below roots in the original
        # tree.
        new_cprofile_tree = {}

        def populate_new_tree(roots):
            for root in roots:
                if new_cprofile_tree not in root:
                    new_cprofile_tree[root] = self.cprofile_tree[root]
                    populate_new_tree(self.cprofile_tree[root]['calls'])

        populate_new_tree(new_roots)
        self.cprofile_tree = new_cprofile_tree
        self.roots = new_roots
dataset/ETHPy150Open j-towns/iprofiler/iprofiler.py/IProfile.delete_top_level/swapped operands of `not in`