how can I clear a dictionary in python

Antoon Pardon apardon at forel.vub.ac.be
Tue Apr 10 01:59:28 EDT 2007


On 2007-04-04, Aahz <aahz at pythoncraft.com> wrote:
> In article <slrnf16ng7.1cf.apardon at rcpc42.vub.ac.be>,
> Antoon Pardon  <apardon at forel.vub.ac.be> wrote:
>>On 2007-04-03, Aahz <aahz at pythoncraft.com> wrote:
>>> In article <KP-dnXOp7ea8IZbbnZ2dnUVZ_oCmnZ2d at comcast.com>,
>>> Larry Bates  <lbates at websafe.com> wrote:
>>>>Aahz wrote:
>>>>> In article <4_SdndYI-pFUbZfbnZ2dnUVZ_hzinZ2d at comcast.com>,
>>>>> Larry Bates  <lbates at websafe.com> wrote:
>>>>>> Marko.Cain.23 at gmail.com wrote:
>>>>>>>
>>>>>>> I create a dictionary like this
>>>>>>> myDict = {}
>>>>>>>
>>>>>>> and I add entry like this:
>>>>>>> myDict['a'] = 1
>>>>>>> but how can I empty the whole dictionary?
>>>>>> just point myDict to an empty dictionary again
>>>>>>
>>>>>> myDict={}
>>>>> 
>>>>> Go back and read Christian's post, then post a followup explaning why his
>>>>> solution is better than yours.  Your explanation should use id().
>>>>
>>>>I believe he (as many new to Python do) are mired in old programming
>>>>thinking that variables "contain" things.  As I'm sure you kno,
>>>>variables point to things in Python.  I don't believe that there are
>>>>lots of other objects pointing to this dictionary.  Perhaps the OP
>>>>can clarify for us.  If there aren't other objects pointing to this
>>>>dictionary it would make NO sense to iterate over a dictionary and
>>>>delete all the keys/values so I tried to read between the lines and
>>>>answer what I believe the OP thought he was asking.
>>>
>>> Then you should explain why you didn't answer the question that was
>>> asked.  Answering a different question without explanation makes your
>>> answer irrelevant at best, wrong at worst.
>>
>>This is not true. If this different question was in fact the intended
>>question instead of the one actually asked. Anwering this different
>>question can be more usefull than answering the one actually asked.
>
> Note carefully that I did not say, "Don't answer the question you think
> should have been asked."  What I said was, "If you answer a different
> question, EXPLAIN WHY."  Is that so difficult to understand?

You are mixing up two things:

On the one hand you are trying to get some moral behaviour accrosss:
People should explain when answering a different question.

On the second hand you are bringing an opinion: If they don't their
answer is irrelevant at best.

If someone disagrees with the second, repeating the first seems
a bit beside the point.

-- 
Antoon Pardon



More information about the Python-list mailing list