[Python-Dev] {}.getitem() (was Re: PEP-0218)
Guido van Rossum
guido@python.org
Thu, 30 Nov 2000 09:10:34 -0500
> > > BTW, I don't get the inspiration for the "first" part in those
> > > names... it makes you think that there's an order to dictionary
> > > items when in reality there isn't.
> >
> > Actually there is -- the (arbitrary) order revealed by .keys().
>
> Hmm, but this can change if you modify the dictionary inside the
> loop or if you modify the dictionary from some other thread.
Let me explain. When Moshe first proposed a .key() method, I was a
bit confused. I thought he wanted a way to get to the i-th key (which
can't be done in O(1) time). Then I thought he wanted a way to get a
random key. Finally I realized that all he wanted was *a* key, and
the first key in the hash table would work fine. Since that's also
the first key of .keys(), I figured "first" was an appropriate
qualification. Sure, it's not guaranteed to remain the first key, but
neither is the first item in a list.
That said, getting rid of the first*() suite and adding popitem()
instead sounds attractive...
--Guido van Rossum (home page: http://www.python.org/~guido/)