Delete dict and subdict items of some name

Paul Rubin no.email at nospam.invalid
Mon Dec 17 18:48:02 CET 2012


Gnarlodious <gnarlodious at gmail.com> writes:
> 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?

Untested:

def unfav(x):
  if type(x) != dict: return x
  return dict((k,unfav(v)) for k,v in x.iteritems() if k != 'favicon')



More information about the Python-list mailing list