|
|
|
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.
Tim Wegener |
05/11/29 - 12:53 am | #
|
|
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).
Dan Everhart |
05/12/01 - 6:02 am | #
|
|
Do you get an email if I reply to this ?
Anyway - added your suggestion in the new "odictbeta2"". 
Fuzzyman |
Homepage |
05/12/01 - 11:33 am | #
|
|
"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.
Fuzzyman |
Homepage |
05/12/02 - 4:10 pm | #
|
|
|
Commenting by HaloScan
|