From my subjective viewpoint, both seem to have merit, but if I were
you I'd be leaning towards the ['a':1, 'b':2] notation.
Re: the 'sorted' varieties: With the new way of iterating through
dictionary keys, I'm not sure why it would be necessary to create new
data structures for sorted lists and dictionaries when it is just as
easy to do the following:
for key in sorted(mydict.keys()):
If this turns out not to be sufficient for performance reasons, you
could always implement a SortedKeysView. Maybe that would help.
Maybe not.
There could also be confusion because vanilla dictionary keys can be
any hashable type, and list elements can be any type.
mydict = { 1: 2, 'hello': [4, 6] }
mylist = [1, 2, 'hello', { 4: 5, 'goodbye': 'hello' }]
The sorted versions would more restrictive in that the types would
need to be orderable, so I think it would be deceptive to the user
(programmer) to try so hard to maintain a similar literal
representation. But hey I'm biased because I like things to be
explicit. And it doesn't really solve the original problem, which was
to eliminate the need to create the ordered dictionary using all the
parentheses and brackets in this line:
OrderedDict([(key1, value1), (key2, value2)])
Re: the 'multi' varieties:
Creating a multiset using something like
multiset((1, 2, 3, 4, 4, 5, 5, 5))
and a multimap/multidict using
multimap({ key1: [ value11, value12 ], key2: [value21, value22] })
doesn't seem all that bad to me. But like I said, I have biases, er,
I mean preferences. (Yeah, "preferences", that's it.)
BTW multimaps in STL are more or less implemented as plain ol' maps
where the values are vectors (lists), like above, with some additional
methods.
- Scott
P.S. Using the 'o' prefix and 'm' prefix, what if you had an ordered
multimap? You'd have to have 'om' or 'mo' before the braces, and now
it's just starting to get weird.