[Python-Dev] {}.getitem() (was Re: PEP-0218)

Guido van Rossum guido@python.org
Thu, 30 Nov 2000 06:52:10 -0500


> > Pronouncement:
> > 
> > It is only efficient to get the *first* item, so let's make that
> > explicit.  The method names will be:
> > 
> >  .firstkey()
> 
> -1
> 
> >  .firstvalue()
> 
> -1
> 
> >  .firstitem()
> 
> +1
> 
> I really think that .firstitem() is both more intuitive and 
> efficient -- .firstvalue() and .firstkey() are simply derivatives
> of this method or how would you define the return value of
> those two methods ?

Yes, firstvalue() and firstkey() return just the value or just the
key.  I can see that the first value is not very useful (since you
don't have the key, you can't mutate the dict).  firstkey() might
be just the ticket e.g. for set implementations.  OTOH you may be
right that it's best to add the minimal number of new methods.

> > Moshe will check in a patch.
> > 
> > Thinking aloud:
> > 
> > Would it be useful to also implement popkey(), popvalue(), popitem(),
> > which would remove the first item and then return the relevant part of
> > it?
> 
> +1
> 
> Same comment as above... .popitem() suffices.

And for minimality reasons I'm at most -0 on it.

--Guido van Rossum (home page: http://www.python.org/~guido/)