deque slicing

Raymond Hettinger vze4rx4y at verizon.net
Wed Sep 15 01:45:17 EDT 2004


> Anyone know why deques don't support slicing?

In part, it is because of the vague notion that slicing is not what deques are
all about.  While it's easy to add a getslice operation, setslice and delslice
require rearranging data outside the slice range.  To me, that is a strong
indicator that an application needs a list instead of a deque.

Even getitem/setitem were a stretch (they perform best at endpoints) and were
added to make deques substitutable for lists in stack/queue applications using
d[0] and d[-1] to implement peekleft() and peekright() operations.

Deques emulate some but not all of the list API.  The parts that match were done
to make deques easier to learn and to make them more substitutable for lists in
stack/queue apps.  The rest of the API was excluded because the list structure
was more appropriate for those operations.


Raymond





More information about the Python-list mailing list