[Grok-dev] Iterativly emptying a grok.container shows weird behavior

Brandon Craig Rhodes brandon at rhodesmill.org
Tue Jun 12 10:36:29 EDT 2007


Tres Seaver <tseaver at palladion.com> writes:

> Dr. Volker Jaenisch wrote:

>> ME VOLKER ASK BUG OR FEATURE? VOLKER NO LIKE BUG! VOLKER NO LIKE FEATURE!

Hilarious!  What a fun mailing list I've joined.  Volker is my
favorite so far.

> Volker might like it more if the container had 100,000 items in it,
> where iterating over the keys rather than getting them all back as a
> list would be much faster.

Nonsense.  If Volker is unhappy getting a huge list from .keys(), he
can call .iterkeys() instead.  Please review the Python interface for
mapping types; it says explicitly that .keys() returns:

   "a copy of a's list of keys"

They key word there is "copy" - the caller has a right to expect that
the sequence of keys he has been returned is a "copy", that is, an
object that now stands independent of the dictionary-like object that
generated it.

Making the decision to turn .keys() into .iterkeys() unilaterally
destroys the whole point of dictionary-like objects supporting both
methods, and, as Volker rightly complains, it breaks many common
Python idioms for working with dictionaries.

-- 
Brandon Craig Rhodes   brandon at rhodesmill.org   http://rhodesmill.org/brandon


More information about the Grok-dev mailing list