The Voidspace Techie Blog

Gravatar Having the items/keys/values methods perform two vastly different behaviours based on the presence of an optional argument smells really bad to me.

Why not just have setitems/setkeys/setvalues methods to do this?
This extra functionality would be used far less often than the normal items/keys/values behaviour.

Putting it in separate methods makes things much clearer for no cost.


Gravatar Amazing. Just today I needed an ordered dictionary for my project, and googling turned up the usenet thread leading to this implementation, a scant two days old. Thanks!

For my needs, I made one enhancement: Adding an optional integer parameter to popitem() implements analogous behavior to list(...).pop(n).

def popitem(self, pos = -1):
...
key = self._sequence[pos]

(I would post the entire modified routine, but the indentation is swallowed when I try.)

This change is backwards compatible with the dict interface and allows me to retrieve items FIFO by using popitem(0).


Gravatar Do you get an email if I reply to this ?

Anyway - added your suggestion in the new "odictbeta2"".


Gravatar "Having the items/keys/values methods perform two vastly different behaviours based on the presence of an optional argument smells really bad to me."

I don't think they're vastly different. The keys method provides access to the the keys sequence for both assigning and setting.

Seems very related.


Name:

Email:

URL:

Comment:  ? 

 

Commenting by HaloScan