[Python-ideas] Allow deleting slice in an OrderedDict
Terry Reedy
tjreedy at udel.edu
Wed Dec 26 08:45:09 CET 2012
On 12/25/2012 8:56 AM, Ram Rachum wrote:
> When I have an OrderedDict, I want to be able to delete a slice of it. I
> want to be able to do:
>
> del ordered_dict[:3]
>
> To delete the first 3 items, like I would do in a list.
>
> Is there any reason why this shouldn't be implemented?
An OrderedDict is a mapping (has the mapping api) with a defined
iteration order (the order of entry). It is not a sequence and does not
have the sequence api. Indeed, a DictList is not possible because dl[2]
would look for the item associated with 2 as a key rather than 2 as a
position. So od[2:3] would *not* be the same as od[2], violating the
usually properly of within-sequence length-1 slices.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list