[Tutor] Remove a dictionary entry

bob gailer bgailer at gmail.com
Sat Sep 18 02:50:12 CEST 2010


  Please always reply-all so a copy goes to the tutor list.

On 9/17/2010 6:20 PM, M. 427 wrote:
> Thank you very much for your answer.
> I wanted to know the pythonic way of doing this, so I did not post my
> buggy trial which was :
>
> version 1 :
> for row in d :
>    if len(row) == 1 :
>      del row # WRONG
>
> Version 2 :
> for i,row in d :
>    if len(row) == 1 :
>      del d(i) # BUG : Syntax error

Thank you for posting code. In the future do so initially. It helps us 
know where to help.

It looks like you learned from version 1.

When you get a syntax error check the manual. When you look at del in:
Python v2.6.4 documentation - The Python Standard Library - 6.8 Mapping 
Type - dict
you will see d[key] - compare that to what you wrote in version 2.

-- 
Bob Gailer
919-636-4239
Chapel Hill NC

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100917/a31b8fd6/attachment.html>


More information about the Tutor mailing list