Delete items in nested dictionary based on value.

Brian L. Troutwine goofyheadedpunk at gmail.com
Thu Sep 14 12:49:08 EDT 2006


> 	Would it not be easier to modify the pretty-printer to ignore such
> entries rather than have to make a duplicate (I presume you have reason
> to need the original dictionary unchanged) dictionary and then delete
> entries that match your "ignore" criteria?

Good question. The data I'm handling relates to books: their ISBN,
pricing information, weight, statistical data for each page, citations
in other books to certain pages, those books statistical data, so on
and so forth. It's too much data, really, but this is what I'm tasked
with handling.

Currently I'm just pretty printing the data, but I'm really cheating
right now. The tool I'm writing is supposed to just collect the data,
strip out all the extranious data based on filters defined at the start
of the collection process and then output all that data to stdout,
where it will be caught by a tool to properly format and display it.

Yesterday morning I got into work, went into deep hack mode, wrote the
entire tool and at the end of the day could not, for the life of me,
figure out the recursion I needed. I suppose I'd spent myself. Who
knows?

Anyway, you are right in that if I did indeed need the original
dictionary unchanged it would be much, much easier to modify the
pretty-printer.

Dennis Lee Bieber wrote:
> On 13 Sep 2006 16:08:37 -0700, "Brian L. Troutwine"
> <goofyheadedpunk at gmail.com> declaimed the following in comp.lang.python:
>
> > arbitrarily large. When pretty printing A, in the context I'm using A
> > for, it's rather helpful to remove all key:value pairs where value is
> > None. So I'd like to be able to define a function dict_sweep to recurse
> > through A and del all the keys with None as a value.
> >
> > I feel like the solution is right on the tip of my tounge, so to speak,
> > but I just can't quite get it. Anyway, here's the best I've come up
> > with:
> >
> 	Would it not be easier to modify the pretty-printer to ignore such
> entries rather than have to make a duplicate (I presume you have reason
> to need the original dictionary unchanged) dictionary and then delete
> entries that match your "ignore" criteria?
> --
> 	Wulfraed	Dennis Lee Bieber		KD6MOG
> 	wlfraed at ix.netcom.com		wulfraed at bestiaria.com
> 		HTTP://wlfraed.home.netcom.com/
> 	(Bestiaria Support Staff:		web-asst at bestiaria.com)
> 		HTTP://www.bestiaria.com/




More information about the Python-list mailing list