[Python-Dev] {}.first[key,value,item] and {}.pop (was Re: {}.getitem())

Barry A. Warsaw barry@digicool.com
Thu, 30 Nov 2000 10:14:53 -0500


>>>>> "PF" == Peter Funk <pf@artcom-gmbh.de> writes:

    PF> Since [].pop() takes in optional index as parameter which
    PF> defaults to the *LAST* element, it would be better to make the
    PF> name explicit: .popfirstitem()

{}.pop() sounds like the right thing given its symmetry with [].pop().

It would have the semantics that it would remove and return a random
/item/ from the dictionary, which the implementation can make the
"first" item for convenience purposes.

It shouldn't dictate though, that {}.pop() == dict.items().pop() or
make any other guarantees about which item gets popped, because other
implementations (or indeed, other mapping-conformant objects) may use
different underlying representations that could make this inefficient.

For added symmetry, {}.pop() should take an optional argument which is
the key of the item to remove and return.

-Barry