Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35061

Re: Delete dict and subdict items of some name

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Delete dict and subdict items of some name
Date 2012-12-18 11:29 -0500
References <943dbf16-1cd1-4844-a666-d8863f5941f8@googlegroups.com> <70a0560d-3ae2-4b24-87f1-dcc3fa6cd4fb@googlegroups.com> <50d0460e$0$6926$e4fe514c@news2.news.xs4all.nl> <bc2f5409-394d-4dcf-9744-7a1db805fd3a@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1021.1355848202.29569.python-list@python.org> (permalink)

Show all headers | View raw


On 12/18/2012 10:27 AM, Gnarlodious wrote:
> On Tuesday, December 18, 2012 3:31:41 AM UTC-7, Hans Mulder wrote:
>> On 18/12/12 06:30:48, Gnarlodious wrote:

>>> from plistlib import readPlist

I do not see this used below.

>>> def explicate(listDicts):
>>> 	for dict in listDicts:
>>> 		if 'FavIcon' in dict:
>>> 			del dict['FavIcon']
>>> 		if 'Children' in dict:
>>> 			dict['Children']=explicate(dict['Children'])
>>> 	return listDicts

>> It would be more Pythonic to return None, to indicate that you've
>> changed the list in situ.

And since it is being changed at the top level (by deletion), it should 
be changed in place all the way down.

>> Since None is the default return value, this means you can leave
>> out the return statement.

  			dict['Children']=explicate(dict['Children'])
would then need to be
  			explicate(dict['Children'])

> But then it only operates on the outer layer,
 > inner layers might get processed but not written.

I believe the above answers your concern. But to be sure it is correct, 
YOU NEED TEST CASES. In fact, your original post should have contained 
at least one non-trivial test case: an input dict and what you wanted it 
to look like after processing. Writing at least some tests before code 
is a great idea.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Delete dict and subdict items of some name Gnarlodious <gnarlodious@gmail.com> - 2012-12-17 09:27 -0800
  Re: Delete dict and subdict items of some name Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-12-17 17:42 +0000
  Re: Delete dict and subdict items of some name Mitya Sirenef <msirenef@lightbird.net> - 2012-12-17 12:43 -0500
  Re: Delete dict and subdict items of some name Paul Rubin <no.email@nospam.invalid> - 2012-12-17 09:48 -0800
  Re: Delete dict and subdict items of some name Dave Angel <d@davea.name> - 2012-12-17 12:50 -0500
  Re: Delete dict and subdict items of some name Tim Chase <python.list@tim.thechases.com> - 2012-12-17 12:30 -0600
  Re: Delete dict and subdict items of some name Mitya Sirenef <msirenef@lightbird.net> - 2012-12-17 16:33 -0500
  Re: Delete dict and subdict items of some name Chris Angelico <rosuav@gmail.com> - 2012-12-18 08:53 +1100
  Re: Delete dict and subdict items of some name Dave Angel <d@davea.name> - 2012-12-17 17:00 -0500
  Re: Delete dict and subdict items of some name MRAB <python@mrabarnett.plus.com> - 2012-12-17 23:08 +0000
  Re: Delete dict and subdict items of some name Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-18 00:17 +0000
  Re: Delete dict and subdict items of some name Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-12-18 00:22 +0000
  Re: Delete dict and subdict items of some name Mitya Sirenef <msirenef@lightbird.net> - 2012-12-17 20:09 -0500
  Re: Delete dict and subdict items of some name Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-12-17 23:44 +0000
  Re: Delete dict and subdict items of some name Dave Angel <d@davea.name> - 2012-12-17 21:13 -0500
  Re: Delete dict and subdict items of some name Gnarlodious <gnarlodious@gmail.com> - 2012-12-17 21:30 -0800
    Re: Delete dict and subdict items of some name Hans Mulder <hansmu@xs4all.nl> - 2012-12-18 11:31 +0100
      Re: Delete dict and subdict items of some name Gnarlodious <gnarlodious@gmail.com> - 2012-12-18 07:27 -0800
        Re: Delete dict and subdict items of some name Terry Reedy <tjreedy@udel.edu> - 2012-12-18 11:29 -0500

csiph-web