Gisle Aas wrote:
On Mar 4, 2009, at 9:01 , Glenn Linderman wrote:
On approximately 3/3/2009 11:22 PM, came the following characters from
the keyboard of Raymond Hettinger:
Perhaps the terminology should be
ordereddict -- what we have here
sorteddict -- hypothetical future type that keeps
itself sorted in key order
+1
-1
Introducing the hypothetical sorteddict would serve to reduce the
likelihood of ordereddict being interpreted as sorteddict among the
small percentage of people that actually read the two lines that might
mention it in the documentation, but wouldn't significantly aid the
intuition of people who first encounter it in someone else's code.
And without an implementation, it would otherwise be documentation
noise, not signal.
Instead of introducing a sorteddict I would instead suggest that the
future should bring an odict with a sort method; possibly also
keys_sorted and items_sorted methods.
I think this would simplify things and putting these methods into the
odict documentation makes it clearer how it actually behaves for people
that just scan the method index to get an impression of what the object
is about.
How about making odict ordered by insertion order, then provide an
optional argument for defining sorter? This optional argument must be a
function/lambda/callable object and must be the first argument.
a = odict(bloh='foo', blah='faa')
a # odict([('bloh', 'foo'), ('blah', 'faa')])
b = odict(lambda a, b: (a[0] < b[0]), bloh='foo', blah='faa')
b # sorted by key: odict([('blah', 'faa'), ('bloh', 'foo')])
c = odict(lambda a, b: (a[1] < b[1]), bloh='foo', blah='faa')
c # sorted by value: odict([('blah', 'faa'), ('bloh', 'foo')])
b = odict(lambda a, b: (a[0] > b[0]), bloh='foo', blah='faa')
b # sorted by key, descending: odict([('bloh', 'foo'), ('blah', 'faa')])
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com