In article <[email protected]>,
Jean-Michel Pichavant <[email protected]> wrote:
>Aahz wrote:
>> In article <[email protected]>,
>> Jean-Michel Pichavant <[email protected]> wrote:
>>>
>>> PS : You're misusing the del statement. It does not remove any object
>>> from mmory, however, it removes the reference to it, the object is still
>>> in memory. They are very few cases where del is usefull in python, so
>>> try to avoid using it as well.
>>
>> The first two sentences are true; the last sentence is completely wrong.
>> I've got lots of code using del, and it's a critically useful element of
>> dictionary manipulation.
>
>Can you please give a short example ? I'm not challenging though, just
>curious.
Let's suppose you want to remove duplicate keys from a second dict:
for k in d1:
if k in d2:
del d2[k]
You could do d2.pop() instead, but I'll bet you'll find that it's
slightly slower, which makes a difference in a tight loop. (Mainly,
though, I learned this idiom long before pop() was available.)
--
Aahz ([email protected]) <*> http://www.pythoncraft.com/
"....Normal is what cuts off your sixth finger and your tail..." --Siobhan
--
http://mail.python.org/mailman/listinfo/python-list