[Tutor] Why is an OrderedDict not sliceable?
Mark Lawrence
breamoreboy at yahoo.co.uk
Sun Jan 24 16:56:30 EST 2016
On 24/01/2016 20:23, Albert-Jan Roskam wrote:
>
> I appear to have confused the terms "sorted" and "ordered" (see the email I just sent to Mark Lawrence). My OrderedDict was sorted on its keys, because I defined the dict using the result of an SQL query that ended with ORDER BY <names of dict keys here>. So in that case I needed a kind of "chameleon" datatype: both a mapping and an indexing type [1]
> [1] https://docs.python.org/2/reference/datamodel.html#object.__getitem__
>
Can you use one of the containers here
http://www.grantjenks.com/docs/sortedcontainers/ ?
If yes it's as simple as:-
pip install sortedcontainers
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Tutor
mailing list