Delete dict and subdict items of some name
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Dec 17 19:17:19 EST 2012
On Mon, 17 Dec 2012 09:27:48 -0800, Gnarlodious wrote:
> Hello. What I want to do is delete every dictionary key/value of the
> name 'Favicon' regardless of depth in subdicts, of which there are many.
> What is the best way to do it?
Firstly, you should assume we know what you are talking about, rather
than explain in clear terms. Never show us an example of your data
structure. That way we can have the entertainment of guessing what the
structure of the data structure is, and coding for data that you don't
care about.
Secondly, never tell us what (if anything) you have already tried, so
that we can share in the same dead-ends and failed attempts. Share and
share alike.
Thirdly, make sure we don't have a clear idea of what you consider
"best", e.g. fastest to write, fastest to execute, most readable, most
easily maintainable, most memory efficient, short enough to be used as a
one-liner, or something else. For bonus points, this shouldn't be clear
in your own mind either.
Fourth, never be clear about the functional requirements. For example, do
you want to mutate the data in place? Or should the original data remain
untouched, and a modified copy be made? By leaving this unstated or
subtly implied, you can ensure that our answers have a 50% chance of
getting it wrong.
If you keep these points in mind, you too can ask open-ended, poor
questions that generate much discussion but don't solve your actual
problem.
Oh wait, I see you already know this! Sorry for the noise.
*wink*
--
Steven
More information about the Python-list
mailing list