[Tutor] Why is an OrderedDict not sliceable?
Mark Lawrence
breamoreboy at yahoo.co.uk
Thu Jan 21 16:02:03 EST 2016
On 20/01/2016 13:33, Albert-Jan Roskam wrote:
> Hi,
>
> Like the subject says: Why is an OrderedDict not sliceable? (From the collections library). Was that an intentional omission, or a mistake? [1]
Plenty of answers on this all ready, but...
>
> Background: I do not use OrderedDict very often, but I thought I could use it to look up street and city names using postcodes ([0-9]{4} [a-z]{2} format). I needed it to be ordered because I also wanted to be able to use bisect, which is needed when the postcode letters are missing. In short: a fast dict lookup for complete postcodes and less fast bisect lookup for in complete postcodes.
>
You appear to be confusing ordered and sorted. There is no way that you
can use bisect on an OrderedDict unless it is sorted in the first place.
> [1] http://stackoverflow.com/questions/30975339/slicing-a-python-ordereddict
>
> Thanks!
>
> Albert-Jan
>
--
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