[Python-ideas] Allow deleting slice in an OrderedDict

Guido van Rossum guido at python.org
Wed Dec 26 17:58:31 CET 2012


Perhaps the desired functionality can be spelled as a method? Would it be
easy to implement?

--Guido

On Wednesday, December 26, 2012, Terry Reedy wrote:

> 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
>
> ______________________________**_________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/**mailman/listinfo/python-ideas<http://mail.python.org/mailman/listinfo/python-ideas>
>


-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121226/5906e077/attachment.html>


More information about the Python-ideas mailing list